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个错误:

最佳答案

您不能在此类中定义变量。

它必须是这样的:

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};

该声明放在类(class)正文中;该定义位于外部。请注意,通常会将类主体放在 header 中,并将定义放在源文件中。

09-28 03:16