可能重复:
C++:对静态类成员的未定义引用
以下 C++ 代码编译良好(使用g++ -c
),但没有链接给出错误:undefined reference to
Abc::X'`
#include <iostream>
using namespace std;
class Abc {
public:
const static int X = 99;
};
int main()
{
Abc a1;
cout << &(Abc::X) << endl;
}
我想知道为什么不允许这样做?