Reputation: 63846
I'd like to set up some common aliases in a shared header, so that individual headers don't have to declare it individually. But I don't want to include the headers for the target namespace in this shared header, only declare the alias. Is this possible?
e.g I want namespace GE = Graphics::Engine;
without including any graphics-engine headers.
Upvotes: 2
Views: 407
Reputation: 208476
I would recommend against it. It can be done and it is simple enough, but what you are effectively doing is forcing your choice of aliases on all users of your headers.
Say that you build a component using this technique and General Electric buys the software, suddenly they get an arbitrary collision of namespaces. You are creating a conflict for no particular reason. Choose a namespace scheme that is simple to use and as unique as possible and then follow it. Adding shortcuts only complicates code (what's the difference between GE::type
and Graphics::Engine::type
?)
Upvotes: 2
Reputation: 131907
Since namespaces are open after being declared, just... declare them up-front:
namespace Graphics{ namespace Engine{} }
namespace GE = Graphics::Engine;
Upvotes: 8
Reputation: 234674
You can if you declare the namespaces beforehand:
namespace Graphics {
namespace Engine {}
}
namespace GE = Graphics::Engine;
Upvotes: 8