Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

krez

nested namespaces in C++

This topic is 5320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am prototyping a large project, and i am using nested namespaces to categorize a lot of the stuff:
namespace ProjectName
{
  namespace SubNamespace
  {
  ...
  };
  namespace OtherSubNamespace
  {
  ...
  };
}; 
i have to type out the two "namespace" lines, and also the two closing brackets. is there a "shortcut" way of doing this? i tried:
namespace ProjectName::SubNamespace
  {
  ...
  };
 
but that doesn''t work. it isn''t too important; i am curious mainly.

Share this post


Link to post
Share on other sites
Advertisement
I don''t know of any "real" quick ways of doing it, but you can always cheat using macros:

#define NAMESPACE2_BEGIN(outer, inner) \
namespace outer { \
namespace inner {

#define NAMESPACE2_END() \
} \
}

// To use them:

NAMESPACE2_BEGIN(ProjectName, SubNamespace)
// ...

NAMESPACE2_END()

Or something like that.

I just write out the namespaces and just neglect to tab them out for large sections (the files I do that to have everything in a single namespace, so it''s not too confusing to read without the tabbing), it''s really not that bad . I think the only C++ project I''m working on has namespaces nested as deeply as 5 levels in parts (most of that stuff is just implementations of interfaces though)...

Share this post


Link to post
Share on other sites
thanks for the tip, although i don''t think it is worth that much effort (i am blocking things together in separate files anyway, so it only happens once per source file).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!