开发者

C++ array initializer. Using enum type

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++2008开发者_如何学运维Ex:

error C2059: syntax error : '{'

error C2334: unexpected token(s) preceding '{'; skipping apparent function body


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜