一个命名空间可以是另一个命名空间的成员吗?
Can one namespace be a member of another namespace?
问题很简单,我可以在另一个命名空间内声明一个命名空间吗?如果是这样,这个命名空间的正确术语是什么,它会被称为 'inner namespace' 还是 'nested namespace',或者可能完全不同?
"can I declare a namespace inside of another namespace?"
是的,您可以根据需要嵌套命名空间
namespace A {
struct thingA;
void funcA();
namespace B {
struct thingC;
void funcB();
namespace C {
struct thingC;
void funcC();
}
}
}
并使用 ::
(范围)运算符引用上述声明:
A::thingA thingA;
A::funcA();
A::B::thingB thingB;
A::B::funcB();
A::B::C::thingC thingC;
A::B::C::funcC();
"what is the correct term for this namespace, would it be called an 'inner namespace' or a 'nested namespace', or perhaps something different altogether?"
而且是的,它通常被称为 'nested namespace'。
问题很简单,我可以在另一个命名空间内声明一个命名空间吗?如果是这样,这个命名空间的正确术语是什么,它会被称为 'inner namespace' 还是 'nested namespace',或者可能完全不同?
"can I declare a namespace inside of another namespace?"
是的,您可以根据需要嵌套命名空间
namespace A {
struct thingA;
void funcA();
namespace B {
struct thingC;
void funcB();
namespace C {
struct thingC;
void funcC();
}
}
}
并使用 ::
(范围)运算符引用上述声明:
A::thingA thingA;
A::funcA();
A::B::thingB thingB;
A::B::funcB();
A::B::C::thingC thingC;
A::B::C::funcC();
"what is the correct term for this namespace, would it be called an 'inner namespace' or a 'nested namespace', or perhaps something different altogether?"
而且是的,它通常被称为 'nested namespace'。