我创建了一个带有静态数据成员的类。但即使.exe
没有创建文件,它也没有被执行。我正在使用Visual C++ express 2010
.
这是我的代码:
#include<iostream>
using namespace std;
class A
{
public:
static int a;
};
int main()
{
A::a = 10;
cout << A::a;
system("pause");
return 0;
}
在编译时,我收到以下错误:
main.obj : error LNK2020: unresolved token (0A00038B) "public: static int A::a" (?a@A@@2HA)
1>main.obj : error LNK2001: unresolved external symbol "public: static int A::a" (?a@A@@2HA)
1>C:\Users\Labeeb\documents\visual studio 2010\Projects\static variables and functions\Debug\static variables and functions.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========