C++数组初始值设定项。使用枚举类型
class ARouter {
enum directions {north, neast, east, seast, south, swest, west, nwest};
static directions gon[] = {north, neast, nwest, east, west, seast, swest, south};
};
你好,有谁知道上面的代码有什么问题吗?
我从 VC++2008Ex 的第二行收到 2 个错误:
错误 C2059:语法错误:“{”
错误 C2334:“{”之前出现意外标记;跳过明显的函数体
class ARouter {
enum directions {north, neast, east, seast, south, swest, west, nwest};
static directions gon[] = {north, neast, nwest, east, west, seast, swest, south};
};
Hi, does anyone know what is the matter with the above code?
I am getting 2 errors for the second line from VC++2008Ex:
error C2059: syntax error : '{'
error C2334: unexpected token(s) preceding '{'; skipping apparent function body
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能在类中定义这样的变量。
它需要类似于:
声明位于类主体中; 定义位于外部。请注意,您通常将类主体放在标头中,并将定义放在源文件中。
You cannot define a variable inside a class like that.
It needs to be something like:
The declaration goes in the class body; the definition lives outside. Note that you'd typically put the class body in a header, and the definition in a source file.