   Having problems in text based game
  So I have these 2 Room objects in my text based game:This is the class:class Room { private:  std::string name;  std::string desc;  std::vector&lt;Item&gt; items;  std::vector&lt;Room&gt; adjRooms; public:  Room(): name("null"), desc(""){ }   Room(const std::string &nm, const std::string &str, const std::vector&lt;Item&gt; &i): name(nm), desc(str), items(i) { }  // Room(const Room &rm): name(rm.name), desc(rm.desc), items(rm.items), adjRooms(rm.adjRooms) { }  // Room& operator=(const Room &rhs);  std::string getDesc() const { return desc; }  void printInfo() const;  Item removeItem(const std::string &itm);   std::string getName() const { return name; }  Room getRoom(const std::string &nm) const;  bool hasItem(const std::string &itm) const;   bool hasRoom(const std::string &rm) const;  void addRoom(Room &rm);};...// the method that should add themselves to each othervoid Room::addRoom(Room &rm){  using namespace std;  adjRooms.push_back(rm);  if(!rm.hasRoom(name))    rm.addRoom(*this);}And here they are made:Room curRoom("Dark", "The chamber is dark.", roomItems);Room nextRoom("Chamber", "A window shines from above", roomItems);nextRoom.addRoom(curRoom);The value of curRoom is changed via this method: handleInput(curRoom);bool handleInput(Room &rm){  using namespace std;  string str;  cout &lt;&lt; '&gt;'; // show a cursor    getline(cin, str);  stringstream ss(str);  string word[2];  ss &gt;&gt; word[0];  ss &gt;&gt; word[1];  ...  else if(word[0] == "go"){    if(rm.hasRoom(word[1])){rm = rm.getRoom(word[1]);    }    else { cout &lt;&lt; "You can't go there." &lt;&lt; endl;    }    pressCont();  }  ...  return true;}The problem is that after curRoom is changed to nextRoom, nextRoom doesn't have curRoom as a room. So I can travel from curRoom to nextRoom, but I cant come back after the curRoom is set to nextRoom.   
  I can't seem to understand what you are trying to do here. Why are you adding rooms? It seems that you have an object that is trying to be itself and navigate itself at the same time. Wouldn't it be easier to have 2 structs, one which will hold the layout of the rooms and another that will hold the info of the room?#define NORTH 0#define EAST 1#define SOUTH 2#define WEST 3struct Room {   // room stuff   std::string name = "NULL";   Room mNorthRoom = w/e;   Room mEastRoom = w/e;   Room mSouthRoom = w/e;   Room mWestRoom = w/e;};struct RoomNavigator {   RoomNavigator(Room rm) {    ChangeRooms(short direction) { switch(direction) {    case NORTH:  if (mNorthRoom.name != "NULL")  {mRoom = &(mRoom->mNorthRoom);  }  else  {std::cout << "Ouch, I hit the wall!\n";  }    break;    case EAST:  etc. etc.    break; }   }   Room *mRoom; // Look in defines to get the idea of direction}; Frankly, I don't think you even need the second struct, you can probably handle it with straight up variables but it'd be easier to deal with because the interface of the struct is smaller >.>   ;  Instead of the NSEW type of movement, I'm trying to have a room that can have a connection to an indefinite amount of rooms by storing the adjacent rooms in a vector. You can go to any of the rooms that are adjacent by typing 'GO [ROOMNAME]'.To clarify also, the handleInput() function is not inside the room class, but just in the main file and is called in my main() function.   ;  Ahh, I see what you mean now. Alright, so you have all the overhead of each room: their names, descriptions, items, and a vector of adjacent Rooms. Then you create two rooms: curRoom and nextRoom. After that, you add curRoom to nextRoom adjrooms vector. Hmm, it's hard for me to say D: (my brain is melting right here :D ) Sorry I can't help ya now, I'm kind of short on time, maybe someone else will be able to help you better than I can :D   ;  Is your hasRoom method working correctly? If it's not, then the second room will not be added to the first. So use your debugger, or print a trace message when adding the room to make sure that it really is added.   ;  Thanks boogyman.I tried some trace messages. The hasRoom method works for sure.I did if(curRoom.hasRoom("Chamber")) cout << "1"; in my main() function after initializing the 2 rooms. 1 shows up so they definitely are added at first.I just realized I made a mistake in my description:Quote:The problem is that after curRoom is changed to nextRoom, nextRoom doesn't have curRoom as a room. So I can travel from curRoom to nextRoom, but I cant come back after the curRoom is set to nextRoomI meant that I can travel from curRoom to nextRoom and then next to cur, but after that, I can't go back to next from there. This makes me think that there is a problem with getRoom() or a problem with the default operator= function. Room Room::getRoom(const std::string &nm) const {  using namespace std;  string tempNm = "", roomWanted = nm;  for(int i = 0; i < roomWanted.size(); i++) // to lower case roomWanted = tolower(roomWanted);  for(vector<Room>::const_iterator it = adjRooms.begin(); it != adjRooms.end(); it++){    tempNm = it->getName();    for(int i = 0; i < tempNm.size();  i++) // to lower case tempNm = tolower(tempNm);    if(tempNm == roomWanted) return *it;  }  return Room();};  milan, I think what you are actually doing is instead of assigning things, you are actually making copies of these rooms. Let me explain here:You make curRoom and assign it to nextRoom. You travel to nextRoom and come back to curRoom, but in reality, you're somewhere completely different because the assignment operator created a completely new object and allocated it into the nextRoom's adjRoom vector. It's a copy, not the room that you start in.I'm not sure if this makes sense D: In order to be in the same rooms, you must make sure that you are accessing the right data and not created multiple instances of it. The best way (I think anyway >.>) to manage this is by creating a variable that will iterate through them via pointers (again, it would be nice to create a set of functions to keep integrity and avoid hardcoding things for easier editing).Lets say there are 5 rooms. The rooms are connected via the adjRooms vector that stores pointers to those rooms.There is also the curRoom pointer which is the room you are currently in. To switch from this room to an adjacent room, you look up if the room is next to the current one you're in, and if it is, you switch the address of curRoom to that of the adjacent room. :DYou don't have to necessarily use the new keyword for this, you can just assign addresses. If you do, make sure you don't forget delete ;].   