title: Override a member function with different return type
body: <p>Consider the example below:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class base
  {
     public:
        virtual int func()
        {
           cout &lt;&lt; "vfunc in base class\n";
           return 0;
        }
  };
  
  class derived: public base
  {
     public:
        double func()
        {
           cout &lt;&lt; "vfunc in derived class\n";
           return 0;
        }
  };
  
  int main()
  {
     base *bptr = new derived;
     bptr-&gt;func();
  
     return 0;
  }
  </code></pre>
  
  <p>The compiler gives an error for the above code that there is conflicting type for the overriden function. Why is it not possible to override a function in the derived class with a different return type ?</p>
  
  <p>I believe, in-order to override a function, the base class virtual method needs to be redefined in the derived class. To redefine a method, the signatures of the methods has to be the same. Since return type is not part of the signature, i believe even if there is difference in return type, the method will still be redefined? In that case for the code above, virtual function <code>func</code> is redefined in the derived class with a different return type. But the compiler throws an error. Is my understanding correct?</p>