title: Nested Structs and accessing data in C++
body: <p>Ok so I am experimenting with making a simple game. I have a struct called Equipment with structs inside it for each part i.e. Helmet, Body, etc. In the Equipment's constructor I have it make objects of the sub structs and in the sub structs constructors i have them initialize string vectors.</p>
  
  <p>So My problem is that in my main function I create an equipment object but when I try to access for example the woodHelm, I get the compile error: ‘struct Equipment’ has no member named ‘helm’. What am I doing wrong? Or is there another way I can do it better?</p>
  
  <p>Here is my Equipment.h (ignore the other sub structs, i havent initialized them yet):</p>
  
  <pre><code>#ifndef EQUIP_H
  #define EQUIP_H
  #include &lt;vector&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  struct Equipment{
      Equipment();
      struct Helmet{
      Helmet(){
          const char* tmp[] = {"Wooden Helmet","1",""};
          vector&lt;string&gt; woodHelm (tmp,tmp+3);
          const char* tmp1[] = {"Iron Helmet","2",""};
          vector&lt;string&gt; ironHelm (tmp1,tmp1+3);
          const char* tmp2[] = {"Steel Helmet","3",""};
          vector&lt;string&gt; steelHelm (tmp2,tmp2+3);
          const char* tmp3[] = {"Riginium Helmet","5","str"};
          vector&lt;string&gt; rigHelm (tmp3,tmp3+3);
      }
      };
      struct Shield{
      Shield(){
          vector&lt;string&gt; woodShield ();
          vector&lt;string&gt; ironShield ();
          vector&lt;string&gt; steelShield ();
          vector&lt;string&gt; rigShield ();
      }
      };
      struct Wep{
      Wep(){
          vector&lt;string&gt; woodSword ();
          vector&lt;string&gt; ironSword ();
          vector&lt;string&gt; steelSword ();
          vector&lt;string&gt; rigSword ();
      }
      };
      struct Body{
      Body(){
          vector&lt;string&gt; woodBody ();
          vector&lt;string&gt; ironBody ();
          vector&lt;string&gt; steelBody ();
          vector&lt;string&gt; rigBody ();
      }
      };
      struct Legs{
      Legs(){
          vector&lt;string&gt; woodLegs ();
          vector&lt;string&gt; ironLegs ();
          vector&lt;string&gt; steelLegs ();
          vector&lt;string&gt; rigLegs ();
      }
      };
      struct Feet{
      Feet(){
          vector&lt;string&gt; leatherBoots ();
          vector&lt;string&gt; ironBoots ();
          vector&lt;string&gt; steelBoots ();
          vector&lt;string&gt; steelToeBoots ();
          vector&lt;string&gt; rigBoots ();
      }
      };
  };
  
  
  #endif
  </code></pre>
  
  <p>Equipment.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Equipment.h"
  
  using namespace std;
  
  Equipment::Equipment(){
      Helmet helm;
      Shield shield;
      Wep wep;
      Body body;
      Legs legs;
      Feet feet;
  }
  </code></pre>
  
  <p>and main.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Player.h"
  #include "Equipment.h"
  #include "Items.h"
  #include "conio.h"
  
  using namespace std;
  using namespace conio;
  
  void init();
  
  int main(int argc, char* argv[]){
      /****INIT****/
      Player p(argv[1],10,1,1);
      Equipment equip;
      Items items;
  
      cout &lt;&lt; clrscr() &lt;&lt; gotoRowCol(3,5) &lt;&lt; "Player Stats: (" &lt;&lt; p.getName() &lt;&lt; ")";
      cout &lt;&lt; gotoRowCol(4,5) &lt;&lt; "HP: " &lt;&lt; p.getHP() &lt;&lt;
      gotoRowCol(5,5) &lt;&lt; "Att: " &lt;&lt; p.getAtt() &lt;&lt;
      gotoRowCol(6,5) &lt;&lt; "Def: " &lt;&lt; p.getDef();
  
      //this is where it is messing up
      p.addHelm(equip.helm.woodHelm);
  
  
      cout &lt;&lt; gotoRowCol(20,1);
  }
  </code></pre>