title: How am i overriding this C++ inherited member function without the virtual keyword being used?
body: <p>I have a small program to demonstrate simple inheritance. I am defining a Dog class which is derived from Mammal. Both classes share a simple member function called ToString(). How is Dog overriding the implementation in the Mammal class, when i'm not using the virtual keyword? (Do i even need to use the virtual keyword to override member functions?)</p>
  
  <p>mammal.h</p>
  
  <pre><code>#ifndef MAMMAL_H_INCLUDED
  #define MAMMAL_H_INCLUDED
  
  #include &lt;string&gt;
  
  class Mammal
  {
      public:
          std::string ToString();
  };
  
  #endif // MAMMAL_H_INCLUDED
  </code></pre>
  
  <p>mammal.cpp</p>
  
  <pre><code>#include &lt;string&gt;
  #include "mammal.h"
  
  std::string Mammal::ToString()
  {
      return "I am a Mammal!";
  }
  </code></pre>
  
  <p>dog.h</p>
  
  <pre><code>#ifndef DOG_H_INCLUDED
  #define DOG_H_INCLUDED
  
  #include &lt;string&gt;
  #include "mammal.h"
  
  class Dog : public Mammal
  {
      public:
          std::string ToString();
  };
  
  #endif // DOG_H_INCLUDED
  </code></pre>
  
  <p>dog.cpp</p>
  
  <pre><code>#include &lt;string&gt;
  #include "dog.h"
  
  std::string Dog::ToString()
  {
      return "I am a Dog!";
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "dog.h"
  
  using namespace std;
  
  int main()
  {
      Dog d;
      std::cout &lt;&lt; d.ToString() &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>output</p>
  
  <pre><code>I am a Dog!
  </code></pre>
  
  <p>I'm using MingW on Windows via Code::Blocks.</p>