C++数组初始值设定项。使用枚举类型

发布于 2024-11-28 05:53:08 字数 356 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆消瘦 2024-12-05 05:53:08

您不能在类中定义这样的变量。

它需要类似于:

class ARouter {
    enum directions {north, neast, east, seast, south, swest, west, nwest};
    static directions gon[];
};

ARouter::directions ARouter::gon[] = {north, neast, nwest, east, west, seast, swest, south};

声明位于类主体中; 定义位于外部。请注意,您通常将类主体放在标头中,并将定义放在源文件中。

You cannot define a variable inside a class like that.

It needs to be something like:

class ARouter {
    enum directions {north, neast, east, seast, south, swest, west, nwest};
    static directions gon[];
};

ARouter::directions ARouter::gon[] = {north, neast, nwest, east, west, seast, swest, south};

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文