【发布时间】:2012-07-15 07:12:45
【问题描述】:
以下 C++ 代码编译良好(使用 g++ -c)但它没有链接给出错误:undefined reference toAbc::X'`
#include <iostream>
using namespace std;
class Abc {
public:
const static int X = 99;
};
int main()
{
Abc a1;
cout << &(Abc::X) << endl;
}
我想知道为什么不允许这样做?
【问题讨论】:
标签: c++ pointers static-variables