wxffles
wxffles

Reputation: 864

Namespace alias scoping issues

I have a header file in which I wish to use a namespace alias while defining a class. However I don't want to expose this alias to anything that includes the header file.

// foo.h
namespace qux = boost::std::bar::baz::qux; // ! exposed to the world
class foo
{
    // can't put a namespace alias here

    // stuff using qux::
};

How can I alias a namespace for a class declaration without it leaking out everywhere?

Upvotes: 7

Views: 1399

Answers (1)

Xeo
Xeo

Reputation: 131799

namespace MyClassSpace
{
namespace qux = boost::std::bar::baz::qux;

class foo
{
  // use qux::
};

}

using MyClassSpace::foo; // lift 'foo' into the enclosing namespace

This is also how most Boost libraries do it, put all their stuff in a seperate namespace and lift the important identifiers into the boost namespace.

Upvotes: 15

Related Questions