title: C++ - Class not updating member properly
body: <p>I've been programming an adventure game and have everything working up until the movement throughout a two-dimensional array dungeon. The Maps are their own struct, while the Character is a class. One of the member variables of the Character class is a Map, <code>curMap</code>, which represents the map the player is currently on. However, in testing in Main.cpp, the works but the map doesn't update properly. Here's the code, after which I'll explain what I've already done.</p>
  
  <p><strong>Maps.h</strong></p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  struct Map {
      vector&lt;string&gt; layout;
      vector&lt;int&gt; exits; //indices in allMaps array
      string name;
      int level;
      Map();
      Map(vector&lt;string&gt; l, vector&lt;int&gt; e, string n, int lvl);
  
  };
  
  extern Map noMap;
  extern Map highashPlainsA, highashPlainsB, highashPlainsC; //Highash Plains
  extern Map alnwick, alnwickForge, alnwickMarket, alnwickInn; //Alnwick
  extern vector&lt;Map&gt; allMaps;
  
  extern vector&lt;string&gt; blankLayout;
  extern vector&lt;string&gt; plainsLayoutA, plainsLayoutB, plainsLayoutC; //Highash Plains
  extern vector&lt;string&gt; alnwickLayout; //Major Towns
  extern vector&lt;string&gt; forgeLayout, marketLayout, innLayout; //Town Buildings 
  </code></pre>
  
  <p><strong>Maps.cpp</strong></p>
  
  <pre><code>#include "Maps.h"
  
  Map::Map() :
      layout(blankLayout),
      exits({0, 0, 0, 0}),
      name("_NO_MAP_"),
      level(0){}
  
  Map::Map(vector&lt;string&gt; l, vector&lt;int&gt; e, string n, int lvl) :
      layout(l),
      exits(e),
      name(n),
      level(lvl){}
  
  Map noMap = Map();
  Map highashPlainsA = Map(plainsLayoutA, {4, 3, 2}, "Highash Plains A", 1);
  vector&lt;Map&gt; allMaps = {noMap, highashPlainsA};
  
  vector&lt;string&gt; blankLayout =
  {"##############################",
   "#                            #",
   "#                            #",
   "#                            #",
   "#                            #",
   "#                            #",
   "#                            #",
   "#                            #",
   "#                            #",
   "##############################"};
  
  vector&lt;string&gt; plainsLayoutA =
  {"##########################33##",
   "# G #####   ####### E ####   2",
   "# # # D # #  G      #        2",
   "# # #  ## ####################",
   "# # ##E#   #   G            G#",
   "#E# G#  G                   G#",
   "# #    ##########E############",
   "# #### #DE  G              ED#",
   "# ###D #DE         G       ED#",
   "################111###########"};
  </code></pre>
  
  <p><strong>Character.h</strong> (I cut out a lot of unimportant code here)</p>
  
  <pre><code>#include "Maps.h"
  #include &lt;iostream&gt;
  
  class Character {
  
  Map curMap;
  
  public:    
      Character();
      ~Character();
      void SetMap(Map map);
      Map GetMap();
  };
  
  extern Character player;
  </code></pre>
  
  <p><strong>Character.cpp</strong> (Left out said unimportant code here as well)</p>
  
  <pre><code>#include "Character.h"
  
  Character::Character() : curMap(highashPlainsA){}
  
  Character::~Character(){}
  
  void Character::SetMap(Map map){
      cout &lt;&lt; "OLD MAP NAME: " &lt;&lt; curMap.name &lt;&lt; "\n";
      curMap = map;
      curMap.layout = map.layout;
      curMap.exits = map.exits;
      curMap.name = map.name;
      curMap.level = map.level;
      cout &lt;&lt; "NEW MAP NAME: " &lt;&lt; curMap.name &lt;&lt; "\n";
  }
  
  Map Character::GetMap(){
      return curMap;
  }
  
  Character player = Character();
  </code></pre>
  
  <p><strong>Main.cpp</strong></p>
  
  <pre><code>#include "Character.h"
  
  int main(){
      player.SetMap(highashPlainsA);
      cout &lt;&lt; "\nSIZE OF CURRENT LAYOUT: " &lt;&lt; player.GetMap().layout.size() &lt;&lt; "\n";
      cout &lt;&lt; "SIZE OF PLAINS A: " &lt;&lt; plainsLayoutA.size() &lt;&lt; "\n";
      cout &lt;&lt; "Name of map: " &lt;&lt; player.GetMap().name &lt;&lt; "\n";
  //  cout &lt;&lt; "Layout of map: \n" &lt;&lt; player.GetMap().layout[0] &lt;&lt; "\n" &lt;&lt; player.GetMap().layout[1] &lt;&lt; "\n" &lt;&lt; player.GetMap().layout[2] &lt;&lt; "\n"&lt;&lt; player.GetMap().layout[3] &lt;&lt; "\n"; // Crashes because for whatever reason the layout size is 0
      return 0;
  }
  </code></pre>
  
  <p><strong>What has been tested:</strong>
  In <code>Character::SetMap()</code> I even tried changing each individual variable, but shouldn't setting the Map as a whole change all of those values? Additionally, in <code>Map::Map(vector&lt;string&gt; l, vector&lt;int&gt; e, string n, int lvl)</code>, I tried it without an initializer list but it still didn't work. I didn't really expect it to, but it was worth a shot I guess.</p>
  
  <p><strong>The issues:</strong></p>
  
  <p><em>Console Output:</em></p>
  
  <pre><code>OLD MAP NAME: Highash Plains A
  NEW MAP NAME: Highash Plains A
  
  SIZE OF CURRENT LAYOUT: 0
  SIZE OF PLAINS A: 10
  Name of map: Highash Plains A
  </code></pre>
  
  <p>The character class <em>does</em> initialize the <code>curMap</code> member, and calls the default constructor to do so. This is intended functionality, because it doesn't matter what map the player is on during setup. However, upon trying to set the map to another precreated Map instance (using <code>SetMap()</code>, everything goes downhill from there. According to the console logging, <code>curMap</code>'s name was set to the correct name (OLD MAP NAME) and it maintained this when set to the new map. But, the layout returns a null vector whereas a log of the direct size of the target vector gives the proper value. What is going on, and how can I fix it?</p>