Joh*_*ohn 3 c++ arrays enums initializer
class ARouter {
enum directions {north, neast, east, seast, south, swest, west, nwest};
static directions gon[] = {north, neast, nwest, east, west, seast, swest, south};
};
Run Code Online (Sandbox Code Playgroud)
嗨,有谁知道上面的代码是什么问题?
我从VC++ 2008Ex获得第二行的2个错误:
错误C2059:语法错误:'{'
错误C2334:'{'之前的意外标记; 跳过明显的功能体
您无法在类中定义变量.
它需要是这样的:
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};
Run Code Online (Sandbox Code Playgroud)
该声明进去类体; 这个定义存在于外面.请注意,您通常将类主体放在标头中,并将定义放在源文件中.