C++ namespace alias in entire class scope

后端 未结 4 1181
庸人自扰
庸人自扰 2021-02-02 07:33

I expected to be able to use a namespace alias in a class declaration but get a compiler syntax error.

struct MyClass
{
    namespace abc = a_big_namespace;
             


        
4条回答
  •  礼貌的吻别
    2021-02-02 08:09

    The scope of a namespace alias is a code block.

    So you can put it in any code block.

    BUT, you can't put it inside a class, because that will mean it's a member of the class.
    A namespace alias can't be a member.

    More about namespace aliases:

    What is the scope of a namespace alias in C++?
    Namespaces

提交回复
热议问题