在下面,我不知道我是否在C#中使用C++来混淆枚举,但我认为你只能访问枚举中的枚举器Forms::shape,这实际上会产生错误.
int main()
{
enum Forms {shape, sphere, cylinder, polygon};
Forms form1 = Forms::shape; // error
Forms form2 = shape; // ok
}
Run Code Online (Sandbox Code Playgroud)
shape如果没有范围运算符,为什么允许在枚举之外访问?如何防止此行为?