Skip to main content
GameDev.net gamedev.net
🔒 Locked

nested namespaces

Started by quasar3d Dec 7, 2003 at 7:11 AM 6 replies 450+ views
Original Post
quasar3d
quasar3d
Are they a good idea? I''ve never seen anyone use them before, but I''ve a case where I think it might be a good idea. I have my engines namespace, and now I''ve the lightwave specific stuff. I will probably have the same classes again, when I will add 3dmax support. So is this a good idea for a nested namespace, or should I just create a new namespace within the global namespace? My Site
Fruny
Fruny
Nested namespaces are perfectly fine.

Additionally, you can have a look at namespace aliasing:

using namespace alias = original;
alias::foo; // refers to original::foo


Before you ask - it is compile-time only, you can''t switch namespaces at run-time. Good try though


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
quasar3d
quasar3d
thanks, It seems handy to me, but I also could imagine one might find it clumpsy or so. It can be pretty anoying to type ns1::ns2::ns3::function.

quote:
Original post by Fruny
Before you ask - it is compile-time only, you can't switch namespaces at run-time. Good try though



Yes, I know that, but else I would have classes named LWMESH and MAXMESH, and LWSURFACE and MAXSURFACE. But I don't want to switch on runtime. They don't even have the same member functions.

My Site

[edited by - Quasar3D on December 7, 2003 9:06:11 AM]
Narcist
Narcist
quote:
Original post by quasar3d
thanks, It seems handy to me, but I also could imagine one might find it clumpsy or so. It can be pretty anoying to type ns1::ns2::ns3::function.



thats what using ns1::ns2::ns3 would be for.. but of course you only do that in the smallest scope..

blizzard999
blizzard999
Nested namespaces are good!

something like this


namespace _3D
{

namespace LW
{
void function(...);
}

}


Out of namespace _3D (at 'global' level) you can access
function in this way


_3D::LW::function(...);


You can access function directly by declaring you want to use _3D::LW namespace


using namespace ::_3D::LW;
function(...);


[edited by - blizzard999 on December 7, 2003 10:49:58 AM]
JOL
JOL
I use a nested namespace for some default values in a small library I''m writing, looks better than #defines and makes more sense aswell, const ''variables''...
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I'm looking for work
antareus
antareus
True that.

I end up putting my usual three namespaces all at the same indentation level and then indenting once. Hacky, but works.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.