小编Kuy*_*nai的帖子

普查员的范围

在下面,我不知道我是否在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如果没有范围运算符,为什么允许在枚举之外访问?如何防止此行为?

c++ enums scope compiler-errors

6
推荐指数
1
解决办法
137
查看次数

标签 统计

c++ ×1

compiler-errors ×1

enums ×1

scope ×1