정적 데이터 멤버로 클래스를 만들었습니다. 그러나 .exe
파일조차도 실행되지 않습니다. Visual C++ express 2010
을 사용하고 있습니다.클래스가 C++에서 정적 변수로 작동하지 않습니다.
#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" ([email protected]@@2HA)
1>main.obj : error LNK2001: unresolved external symbol "public: static int A::a" ([email protected]@@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 ==========
'system ("pause")'을 사용하지 마십시오. 나쁜 습관입니다. –
이 질문에 대한 5 천만 시간 만 묻습니다. – john