Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

namespace within class

10 views
Skip to first unread message

carlosp

unread,
Feb 24, 2009, 11:06:24 AM2/24/09
to
Hello, I am trying to organize a big project. At this point I have a
class with ~100 methods. I would like to organize them in a similar
way as with namespaces, but the declaration

namespace myNamespace { }

within the class gives an error

g++ -DNOWARNDRMT -Wall -Wextra -o 2dmera 2dmera.cpp -litpp
./qubit_gate.cpp:476: error: expected unqualified-id before
'namespace'
make: *** [2dmera] Error 1
nike:mera2d carlosp$


What would be the best way to organize my big class??? (I am still
sort of rookie in c++)

Thanks!

DerT...@web.de

unread,
Feb 24, 2009, 11:25:54 AM2/24/09
to
On 24 Feb., 17:06, carlosp <carlospgma...@gmail.com> wrote:
> Hello, I am trying to organize a big project. At this point I have a
> class with ~100 methods. I would like to organize them in a similar
> way as with namespaces, but the declaration
>
> namespace myNamespace { }
>
> within the class gives an error

That's right, namespaces inside classes are not allowed, and when you
think about, this wouldn't make much sense. What would like to achieve
with namespaces inside classes?

> What would be the best way to organize my big class??? (I am still
> sort of rookie in c++)

This depends. Having a class with 100 methods doesn't have to be bad
design (the CWnd class of MS's MFC has about this number of methods).
In general, however, a class with too many methods is a strong
indicator of bad design. In such a case you should try to separate the
class into several classes, each of them with a smaller coherent
interface. If your source code is not confidential, you could post a
small snapshot of the class so that we can help you better.

Regards,
Stuart

carlosp

unread,
Feb 24, 2009, 11:47:40 AM2/24/09
to

Thank you very much. well actually it has a big number of small
routines that move sutff and so on. I am not really willing to create
new clases, that seems to be to much of an effort.

So in order to have it available everywhere I have it in a svn server.
It cannot be compiled as it is downloaded as it requires some other
files that are not there. Still you can take a look. The file I want
to organize is "qubit_gate.cpp". I am also looking forward to any
suggestions regarging programing style!

Download with
svn co https://mera2d.svn.sourceforge.net/svnroot/mera2d

Thanks,
Carlos

Daniel Pitts

unread,
Feb 24, 2009, 10:11:22 PM2/24/09
to

Is the class concerned with exactly one thing? If not, then you realy
should consider separating your concerns, possibly moving members into
new classes which stand-alone, and using composition.

How much effort is it to create new classes, really? Adding namespaces
won't actually improve your design, but splitting the class into several
classes -- each with their own core concern -- likely will improve it
significantly.

Also, think about this: Code is read and modified a lot more often than
it is written. If you don't spend a little extra time/effort to make it
clean now, you'll spend a lot of time and effort to deal with it later.


--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

carlosp

unread,
Feb 26, 2009, 6:24:50 AM2/26/09
to
On Feb 25, 4:11 am, Daniel Pitts

Thanks a lot! I will consider your suggestion, though its not clear
for me at this point how to proceed, regarding design. I guess I'll
have to think a bit...

Thanks for your help!

0 new messages