<分区>
Possible Duplicate:
Access issue regarding static variable
我遇到了一个看似微不足道的问题,但我似乎无法找出原因。
我有一个叫做存储的类。 头文件:
#include <string>
using namespace std;
#include "Player.h"
class Storage {
public:
static void Initialise();
static string GetInformation();
private:
static Player player;
};
CPP 文件:
string Storage::GetInformation() {
string returnString = "";
// Get the players money
// Convert it to a string
string money("money");
stringstream out;
out << player.GetMoney();
money = out.str();
returnString += "Money: " + money + "\n";
// Get the players ship information
returnString += player.GetShipInformation();
// Get the players current location
returnString += player.GetCurrentLocation();
return returnString;
}
void Storage::Initialise() {
}
这给出了一个错误:“对 `Storage::player' 的 undefined reference ”。我试过用谷歌搜索它并进行调整,但我似乎找不到任何有用的东西。如果有人能为我指出正确的方向让我看一篇文章,那就太好了,因为我不确定要搜索什么术语才能获得正确的答案。