我尝试使用下面的代码:为什么我不能在初始化程序列表中初始化静态变量?
class Test
{
private:
static int x;
public:
Test(int i) : x(i) {}
};
main()
{
Test a(5);
}
但是,后来我得到了错误:
‘int Test::x’ is a static data member; it can only be initialized at its definition
有什么不对上述实施?
因为它没有有意义吗? – 2013-03-20 04:20:02
请注意,您可以在类级别初始化静态const积分。 – Synxis 2013-03-20 09:00:03