位于C嗨IAM初学者++我有静态方法类,我不能访问它们它将引发我一个错误
1>------ Build started: Project: CPractice, Configuration: Debug Win32 ------
1> Source.cpp
1>Source.obj : error LNK2001: unresolved external symbol "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > CPractice::name" (?name@CPractice@@0V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A)
1>c:\users\innersoft\documents\visual studio 2012\Projects\CPractice\Debug\CPractice.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
这里是我的代码
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <string>
using namespace std;
class CPractice
{
public:
static void setName(string s)
{
name = s;
}
static string getName()
{
return name;
}
private:
static string name;
};
int main()
{
CPractice::setName("Name");
cout << "\n" << CPractice::getName();
system("PAUSE");
return EXIT_SUCCESS;
}