今天在进行C++编程时,发现了一些小错误,里面的报错为:
编译器提示我不能在类内初始化非const static成员变量,经过查阅相关书籍和资料后得到的原因为:
C++标准只允许static constant intergral或者枚举类型的数据在类内进行初始化。
引用:C++03 9.4.2 Static data members
§4 If a static data member is of const integral or const enumeration type, its declaration in the class definition can specify a constant-initializer which shall be an integral constant expression (5.19). In that case, the member can appear in integral constant expressions. The member shall still be defined in a namespace scope if it is used in the program and the namespace scope definition shall not contain an initializer.(如果一个静态数据成员是constant integral或者const numeration类型,那么它类内的声明中如果包含定义部分,定义部分应该是一个integral constant表达式。在这个