【发布时间】:2011-11-06 11:20:22
【问题描述】:
在下文中,我不知道我是否将 C# 中的枚举与 C++ 混淆了,但是
我以为您只能使用 Forms::shape 访问枚举中的枚举器,这实际上会产生错误。
int main()
{
enum Forms {shape, sphere, cylinder, polygon};
Forms form1 = Forms::shape; // error
Forms form2 = shape; // ok
}
为什么shape 允许在没有范围运算符的情况下在枚举之外访问,我该如何防止这种行为?
【问题讨论】:
标签: c++ enums compiler-errors scope