How do I shorten a namespace within a class?

98 Views Asked by At

I want to shorten a namespace for use within MyClass, for example by using namespace or defining an alias:

namespace foo = really::loong::name::space;

class MyClass {
private:
    foo::FooClass f;
// ...
};

However, this pollutes the global namespace and risks affecting code elsewhere. I could wrap the above code within a name space, but I'm quite happy with the name MyClass and I'd rather not have to refer to it as mynamespace::MyClass. Is there any way around this?

1

There are 1 best solutions below

1
Aykhan Hagverdili On

but I'm quite happy with the name MyClass and I'd rather not have to refer to it as mynamespace::MyClass.

Put the class in a namespace anyway so it doesn't pollute the global namepsace either. If your users prefer short names, they can add a using mynamespace::MyClass.