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:'{'之前的意外标记;跳过明显的功能体
答案 0 :(得分:5)
您无法在类中定义变量。
它必须是:
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};
声明进入类体; 定义生活在外面。请注意,您通常将类主体放在标题中,将定义放在源文件中。