【发布时间】:2015-05-01 12:31:44
【问题描述】:
#pragma once
class B
{
private:
static int s_nValue;
public:
B();
~B();
static int GetValue() { return s_nValue; }
static void SetValue(int value){ s_nValue = value; }
};
int _tmain(int argc, _TCHAR* argv[])
{
int i = 0;
B::SetValue(5);
std::cout << B::GetValue();
cin>> i;
return 0;
}
我正在尝试掌握静态函数的使用。在这种情况下,SetValue() 和 GetValue() 在类 B 中定义。它们在 main 中没有对象定义的情况下被调用。这应该可以,但是我收到了一个未解决的外部符号错误 2001。预编译的标头选项已关闭。
我怎样才能摆脱这个错误?
使用 MS Visual Studio 2012
【问题讨论】: