How to Rename Namespace?

23 11 2008

Namspaces are introduced to have logical grouping of classes. But as the framework grows you could often find that the namespace length grows which make the usage more difficult.


For instance, one namespace i’ve encountered is like this –

namespace Company
    namespace Product
        namespace Communication
            namespace Event
                class CEventEx

How much I’ve to go inside to address a class? Well, in big frameworks this kind of deep hierarchy is unavoidable. But, its a fact that it causes trouble to developer who uses it. Well, is there any idea to avoid that?

Well, you can rename the namespace to much more smaller one! Have a look at the code snippet below.

// Rename the namespace
namespace ThirdPartyEvent = Company::Product::Communication::Event;
// Create the object by using renamed namespace.
ThirdPartyEvent::CEventEx objEvent;

There are still a lot of gems inside C++. isn’t it? 😉

Targeted Audience – Beginners.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: