开发者

Namespace alias scoping issues

I have a header file in which I wish to开发者_C百科 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜