title: Virtual Method not calling dervied class method. - C++
body: <p>I have a method in both the base class and the derived class.  When I call this method on an object in the derived class it calls the base class method and not the derived class method.  Here is my code:</p>
  
  <p>Person.h</p>
  
  <pre><code>class Person
  {
  ...
  public:
  ...
      virtual void coutPerson();
  };
  </code></pre>
  
  <p>Person.cpp</p>
  
  <pre><code>void Person::coutPerson() {
      cout &lt;&lt; name &lt;&lt; endl;
      birthday.coutDate();
      phoneNumber.coutPhoneNumber();
      cout &lt;&lt; city &lt;&lt; ", " &lt;&lt; state &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Student.h</p>
  
  <pre><code>class Student : public Person
  {
  ...
  public:
  ...
      virtual void coutPerson();
  };
  </code></pre>
  
  <p>Student.cpp</p>
  
  <pre><code>void Student::coutPerson() {
      cout &lt;&lt; "DEBUG: Student::coutPerson()" &lt;&lt; endl;
      //Person::coutPerson();
      cout &lt;&lt; "Dorm Room: " &lt;&lt; this-&gt;dorm &lt;&lt; " " &lt;&lt; this-&gt;dormRoom &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Object created at: <code>addPerson&lt;Student&gt;(personVector);</code>
  When object is created it is created as a Student because it calls the Student construtor.
  Method called at: <code>personVector[num-1].coutPerson();</code>
  The Student object is the one being told to coutPerson because it is displaying the info that I gave it when I created the Student object.</p>
  
  <pre><code>template&lt;typename T&gt; void addPerson(vector&lt;Person&gt; &amp;personVector) {
      T p;
      personVector.push_back(p);
  }
  </code></pre>
  
  <p>When the coutPerson() method is called on a Student object it only couts the name, birthday, phoneNumber, and city &amp; state.  What is wrong with this code?  It should be calling the Student coutMethod...</p>
  
  <p>Thanks!</p>