title: Override Methods in C/C++ like Delphi
body: <p>In Delphi we have an option to do a thing like this:</p>
  
  <pre><code>TClass1 = class
    procedure Test; virtual;
  end;
  
  TClass2 = class(TClass1)
    procedure Test; override;
  end;
  </code></pre>
  
  <p>So in code, If I create an instance of TClass2, even if I cast the object like:</p>
  
  <pre><code>TClass1(ObjectClass2).Test;
  </code></pre>
  
  <p>The application will call the function declared on TClass2.</p>
  
  <p>But in C/C++ I could not find a way to do this.</p>
  
  <p>If I declare some void as virtual and implement the same void in the children class when I do the cast to the parent class it'll not use the implementation of the children class.</p>
  
  <p>Does anyone know how I can reproduce the behavior of Delphi in C/C++ ? </p>
  
  <hr>
  
  <p>New informations:
  These are my files.</p>
  
  <pre><code>---------------------- File Filho.hpp
  #ifndef FILHO_HPP
  #define FILHO_HPP
  #include "Pai.hpp"
  
  class Filho : public Pai {
  public:
      Filho();
      virtual ~Filho();
      void metodoX();
  };
  
  Filho::Filho() {}
  Filho::~Filho() {}
  
  void Filho::metodoX() {
      std::cout &lt;&lt; "Hello Filho!" &lt;&lt; std::endl;
  }
  #endif
  
  
  ---------------------- File Pai.hpp
  #ifndef PAI_HPP
  #define PAI_HPP
  #include &lt;iostream&gt;
  
  class Pai {
  public:
      Pai();
      virtual ~Pai();
      virtual void metodoX();
  };
  Pai::Pai() {}
  Pai::~Pai() {}
  
  void Pai::metodoX() {
      std::cout &lt;&lt; "Hello Pai!" &lt;&lt; std::endl;
  }
  
  #endif
  
  ---------------------- File Main.hpp
  #include "Pai.hpp"
  #include "Filho.hpp"
  
  int main() {
      Pai pai;
      pai.metodoX();      //Here output the msg Hello Pai!
  
      Filho filho;           
      filho.metodoX();    //Here output the msg Hello Filho!
  
      ((Pai) filho).metodoX(); //Here output the msg Hello Pai! , but here if I use the directive 'override' in Delphi, the output will be Hello Filho!. Here is my doubt.
      return 0;
  }
  </code></pre>