<分区>
我在 A.h 中有以下代码:
class A
{
public:
...
private:
...
const int X = 1;
float Y[X];
...
};
如果项目中只包含头文件 A.h,则可以正常编译。但是如果我在 A.cpp 中包含 A.h,它会给我如下奇怪的错误:
... warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
... error: invalid use of non-static data member 'A::X'
... error: from this location
即使我更改 const int X = 1;
(尽管我需要它作为常量参数),也没有任何变化。
附注如果有意义的话,我正在使用 Qt 5.1
附:实际上使它 static
修复了错误。但为什么我必须这样做?