title: c++ class inheritance, undefined reference to 'Class::Constructor()'
body: <p>Edit: Posted fixed code at the bottom.  Thanks everyone for your help!</p>
  
  <p>I am just learning c++ and am having trouble with inheritance.  I have searched and searched and tried anything I can but I can not get this code to compile while retaining the functionality that I want it to have.  </p>
  
  <p>I feel like I am making a stupid mistake or maybe I'm just missing some big concept, but if anyone could take a look at it I'd really appreciate it!</p>
  
  <p>If I comment out the the 3 lines in the StarSystem Constructor that create objects, then it compiles, so I know this has to do with the issue.</p>
  
  <pre><code>    #include &lt;iostream&gt; 
      #include &lt;vector&gt;
      #include &lt;string&gt;
      #include &lt;stdlib.h&gt;
      #include &lt;time.h&gt;
  
      using namespace std;
  
      class SystemBody
      {
          public:
              SystemBody();
              int systembodyindex;
              int starsystemindex;
  
              SystemBody(int systembodyindex, int starsystemindex)
              {
                  cout &lt;&lt; "StarSystem " &lt;&lt; starsystemindex &lt;&lt; ": creating empty SystemBody " &lt;&lt; systembodyindex &lt;&lt; endl;
              }
      };
  
  
      class Star : public SystemBody
      {
          public:
              Star();
              string startype;
  
              Star(int systembodyindex, int starsystemindex)
              {
                  cout &lt;&lt; "StarSystem " &lt;&lt; starsystemindex &lt;&lt; ": converting empty SystemBody into Star " &lt;&lt; systembodyindex &lt;&lt; endl;
              }
      };
  
      class Planet : public SystemBody
      {
          public:
              Planet();
              string planettype;
  
              Planet(int systembodyindex, int starsystemindex)
              {
                  cout &lt;&lt; "StarSystem " &lt;&lt; starsystemindex &lt;&lt; ": converting empty SystemBody into Planet " &lt;&lt; systembodyindex &lt;&lt; endl;
              }
  
      };
  
      class ExitNode : public SystemBody
      {
          public:
              ExitNode();
              vector&lt;int&gt; connectedindexlist;
              ExitNode(int systembodyindex, int starsystemindex)
              {
                  cout &lt;&lt; "StarSystem " &lt;&lt; starsystemindex &lt;&lt; ": converting empty SystemBody into Exit Node " &lt;&lt; systembodyindex &lt;&lt; endl;
              }
  
  
      };
  
  
      class StarSystem
      {
          public:
              StarSystem();
              int starsystemindex;
              vector&lt;StarSystem&gt; connectedlist;
              vector&lt;Planet&gt; planetlist;
  
              StarSystem(int index)
              {
                  starsystemindex = index;
                  cout &lt;&lt; "--Creating StarSystem: " &lt;&lt; starsystemindex &lt;&lt; endl;
                  int numberofbodies = (rand() % 4) + 2;
                      for ( int i = 0; i &lt; numberofbodies; i +=1 )
                      {
                          if ( i == 0 )
                          {
                              Star body(i, starsystemindex);
                          }
                          else if ( i == numberofbodies )
                          {
                              ExitNode body(i, starsystemindex);
                          }
                          else
                          {
                              Planet body(i, starsystemindex);
                          }
  
                      }
  
              }
  
              void addConnection(StarSystem connectedstarsystem)
              {
                  cout &lt;&lt; "--StarSystem " &lt;&lt; starsystemindex &lt;&lt; ": Adding connection to StarSystem " &lt;&lt; connectedstarsystem.starsystemindex &lt;&lt; endl;
                  connectedlist.push_back(connectedstarsystem);
              }
  
      };
  
  
  
      int main()
      {
          srand(time(0));
          StarSystem starsystem0(0);
          return 0;
      }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>thanks to everyone for your help! just posting the fixed code here in case any one in the future might find this useful.</p>
  
  <pre><code>#include &lt;iostream&gt; 
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  using namespace std;
  
  class SystemBody
  {
      public:
          int systembodyindex;
          int starsystemindex;
          SystemBody ( )
          {
              cout &lt;&lt; "----SystemBody BEING CREATED WITH NO PARAMETERS" &lt;&lt; endl;
          }
          SystemBody ( int bodyindex, int systemindex )
          {
              systembodyindex = bodyindex;
              starsystemindex = systemindex;
              cout &lt;&lt; "----StarSystem " &lt;&lt; starsystemindex &lt;&lt; ": creating empty SystemBody " &lt;&lt; systembodyindex &lt;&lt; endl;
          }
  
  };
  
  
  class Star : public SystemBody
  {
      public:
          Star ( int bodyindex, int systemindex ) : SystemBody ( bodyindex, systemindex )
          {
              cout &lt;&lt; "----StarSystem " &lt;&lt; starsystemindex &lt;&lt; ": converting empty SystemBody into Star " &lt;&lt; systembodyindex &lt;&lt; endl;
          }
  };
  
  
  class Planet : public SystemBody
  {
      public:
          Planet ( int bodyindex, int systemindex ) : SystemBody ( bodyindex, systemindex )
          {
              cout &lt;&lt; "----StarSystem " &lt;&lt; starsystemindex &lt;&lt; ": converting empty SystemBody into Planet " &lt;&lt; systembodyindex &lt;&lt; endl;
          }
  };
  
  class ExitNode : public SystemBody
  {
      public:
          ExitNode ( int bodyindex, int systemindex ) : SystemBody ( bodyindex, systemindex )
          {
              cout &lt;&lt; "----StarSystem " &lt;&lt; starsystemindex &lt;&lt; ": converting empty SystemBody into ExitNode " &lt;&lt; systembodyindex &lt;&lt; endl;
          }
  };
  
  
  class StarSystem
  {
      public:
          int starsystemindex;
          vector&lt;StarSystem&gt; connectedlist;
          vector&lt;Planet&gt; planetlist;
  
          StarSystem ( int index )
          {
              starsystemindex = index;
              cout &lt;&lt; "--Creating StarSystem: " &lt;&lt; starsystemindex &lt;&lt; endl;
              int numberofbodies = (rand() % 4 ) + 2;
              for ( int i = 0; i &lt;= numberofbodies; i +=1 )
              {
                  if ( i == 0)
                  {
                      Star body(i, starsystemindex);
                  }
                  else if ( i == numberofbodies )
                  {
                      ExitNode body(i, starsystemindex);
                  }
                  else
                  {
                      Planet body(i, starsystemindex);
                  }
              }
          }
  };
  
  int main()
  {
  
      srand(time(0));
      StarSystem starsystem0(0);
      return 0;
  }
  </code></pre>