ここに別の初心者がいるので、少しセンスのある人が私を助けてくれることを願っています! 私の質問が述べているように、私は単純にプレイヤー クラスを作成しようとしています (これは RPG ゲーム用です)。ただし、表示されているコードは最新のもので、これを行う複数の方法を試しましたが、さまざまなエラーが発生し続けています。Microsoft Visual C++ 2010 Express を使用していますが、現在直面しているエラーは次のとおりです。
1>player.obj: エラー LNK2001: 未解決の外部シンボル "private: static class std::basic_string,class std::allocator > Player::m_playerName" (?m_playerName@Player@@0V?$basic_string@DU?$char_traits@ D@std@@V?$allocator@D@2@@std@@A)
これが十分な詳細であることを願っています!私が作成した残りのコード/ファイルは次のとおりです。
ゲーム.cpp
#include <iostream>
#include "player.h"
using namespace std;
int main()
{
Player main;
main.setStats();
main.showStats();
int stopper;
cin >> stopper;
return 0;
}
player.h
#include <string>
class Player
{
public:
Player();
void showStats();
void setStats();
private:
int m_playerLVL;
static std::string m_playerName;
};
player.cpp
#include "player.h"
#include <iostream>
#include <string>
using namespace std;
Player::Player()
{
cout << "Please enter your name: ";
string playerName;
getline (cin, playerName);
m_playerName = playerName;
}
void Player::showStats()
{
cout << "Hello, i am " << m_playerName << "and i am lvl " << m_playerLVL;
}
void Player::setStats()
{
m_playerLVL = 1;
}