开发者

Namespace alias scoping issues

开发者 https://www.devze.com 2023-03-18 07:44 出处:网络
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.

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

精彩评论

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