title: C++ inheritance function override
body: <p>I am pretty new to C++ and I am coming from Java/C#. </p>
  
  <p>I know that in Java and C# you can make a class, have another class inherit from it, and override its function. You can then make list of the parent class and insert to this list objects of the child class. After that you can use it's functions that were overridden.</p>
  
  <p>Example:</p>
  
  <pre><code>public class Parent
  {
    public virtual void test()
    {
      Console.WriteLine("test");
    }
  }
  
  public class Child : Parent
  {
    public override void test()
    {
      Console.WriteLine("test2");
    }
  }
  </code></pre>
  
  <p>Usage:</p>
  
  <pre><code>List&lt;Parent&gt; tests = new List&lt;Parent&gt;();
  tests.Add(new Child());
  tests[0].test();
  </code></pre>
  
  <p>Output:</p>
  
  <blockquote>
  <pre><code>test2
  </code></pre>
  </blockquote>
  
  <p>In C++, <strong><em>when I do this with <code>std::vector</code></em></strong>, it calls the parent's member function, rather than that of the child. </p>
  
  <p>How can I do the above in C++?</p>