title: Why am i getting this error? "Child undeclared?
body: <p>I'm writing some code to show inheritance.
  In doing so, i want to illustrate it by having a base class that contains a vector of pointers that can hold object pointers of the derived class.</p>
  
  <p>I'm getting this error that the "Child class is undeclared" in the base function "void addChild(string nm, string sm)" in the Parents class (base class). I do understand that it maybe out of scope in the base class.
  Can someone provide me with a solution to this where i can still be able to instantiate an object of the derived class from within the base class.
  I want to have everything done within the base class.
  Please clarify if this is ok and is a good practice. If not, please suggest some ideas.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  class Parents // base class
  {
      vector &lt;Parents*&gt; fam;
  
  protected:
      string firstName;
      string lastName;
  public:
      Parents()
      {
          //default constructor              
      }
      Parents(string fn, string ln)
      {
          firstName = fn;
          lastName = ln;
      }
      void displayChildren()
      {
          if (fam.empty())
          {
              cout &lt;&lt; "Vector is empty" &lt;&lt; endl;
          }
          else
          {
              for (unsigned int i = 0; i &lt; fam.size(); i++)
              {
                  std::cout, fam.at(i);
              }
          }
      }
      void displayParentsInfo(Parents&amp; const par)
      {
          cout &lt;&lt; "First name : " &lt;&lt; par.firstName &lt;&lt; endl;
          cout &lt;&lt; "Last name  : " &lt;&lt; par.lastName &lt;&lt; endl;
      }
      void addChild(string nm, string sm)
      {
          Child* c1 = new Child(nm, sm);      
          fam.push_back(c1);
      }
  };
  
  class Child : public Parents //derived class
  {
      string firstname;
      string surname;
  
  public:
      Child()
      {
          //default constructor
      }
      Child(string a, string b)
      {
          firstname = a;
          surname = b;
      }
      //~Child()
      //{
          //destructor called
      //}
      void displayChildInfo(Child &amp; const c)
      {
          cout &lt;&lt; "Child's firstname : " &lt;&lt; c.firstname;
          cout &lt;&lt; "Child's surname   : " &lt;&lt; c.surname;
      }
  };
  </code></pre>
  
  <p>Cheers!</p>