title: Overriding a member function with derived type in C++
body: <ul>
  <li><p>It is possible to override parameters with a derived class similar to what is show in <code>B::g()</code> or <code>B::h()</code>?  </p></li>
  <li><p>If not is there a sensible way to achieve the same thing?</p></li>
  <li><p>It makes sense why <code>B::i()</code> does not work, but why not the others?</p></li>
  </ul>
  
  <p>My goal is to use <code>r</code> in <code>B::g()</code> as type <code>Y</code>.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>struct X {};
  struct Y : X {};
  
  struct A {
      virtual void f(X q);
      virtual void g(X&amp; r);
      virtual void h(X* s);
  
      virtual X i();  // note: overridden function is 'virtual X A::i()'
      virtual X* j();
  };
  
  struct B final : A {
      void f(Y q) final;   // error: 'void B::f(Y)' marked 'final', but is not virtual
      void g(Y&amp; r) final;  // error: 'void B::g(Y&amp;)' marked 'final', but is not virtual
      void h(Y* s) final;  // error: 'void B::h(Y*)' marked 'final', but is not virtual
  
      Y i() final;   // error: invalid covariant return type for 'virtual Y B::i()'
      Y* j() final;  // works
  };
  
  
  </code></pre>