You are declaring the name of the player to be static
:
static std::string m_playerName; // DON'T MAKE IT STATIC!
That's semantically incorrect, and removing static
happens to solve your problem. Each instance of Player
should associate a different value to m_playerName
(because each player has their own name). Declaring a data member static
makes it global for the whole Player
class (i.e. it is not given a per-instance value, but one global value which is the same for all Player
objects). That doesn't sound like something you would want.
Now if for any reason you really meant to declare this as a static
data member, then you should provide a definition for it at the global namespace scope:
std::string Player::m_playerName;
The linker is complaining about the lack of such a definition.