鉴于以下情况:
namespace otherns
{
enum MyEnum_e { MyEnum_YES, MyEnum_NO };
}
namespace myns
{
typedef otherns::MyEnum_e MyEnum_e;
}
为什么以下内容无效?
int e = myns::MyEnum_YES;
我收到编译器错误说明:
'MyEnum_YES' is not a member of 'myns'
最佳答案
因为枚举值位于命名空间 otherns
中,而不是作为 MyEnum_e
的子项:要引用 MyEnum_YES
,您键入 otherns::MyEnum_YES
.
你可以试试这个:
namespace otherns
{
namespace MyEnum_e_space {
enum MyEnum_e { MyEnum_YES, MyEnum_NO };
}
using namespace MyEnum_e_space;
}
namespace myns
{
using namespace otherns::MyEnum_e_space;
}
尽管不鼓励使用 using
..
关于c++ - typedef 一个现有的枚举类型,可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5820159/