Class value accessible from multiple files and functions c++ -


i apologize before-hand if question has been asked before.

i put skills google use , still nothing if question has been answered before please link answer , i'll end question.

anyway, out of way, problem have class "player.hpp" , corresponding "player.cpp" in have defined location system "player" can initialize value fine (which 1 of functions of class) when player goes "play()" function (which holds bones of game , located in .cpp file) when use function location stored there nothing stored... appreciated.

if don't understand i'm asking please comment , i'll elaborate.

code below:

//player.hpp class player { public:     std::string getlocation();     void setlocation(std::string local);     void initlocation();  private:     std::string location; };  //player.cpp void player::initlocation() {     player::location = "b0";     return; } std::string player::getlocation() {     return player::location; } void player::setlocation(std::string local) {     player::location = local;     return; }  //main.cpp //.... player plays; plays.initlocation(); //....  //game.cpp //... player plays; std::string local = plays.getlocation(); //when check there isn't value gets stored... if(local.find(...)...) 

again, appreciated , apologize if question has been asked.

edit:

i guess should have clarified want change value stored player progresses room room (as zork style game i'm making)

assuming each instance of player in separate location, can resolve issue initializing player's location default location in constructor. removes need initlocation(), , there no need call main.cpp.

//player.hpp class player { public:     std::string getlocation();     void setlocation(std::string local);      player () : location("b0") {}  private:     std::string location; };