title: Overloading of virtual functions
body: <p>I was asked this question in an interview. I was not able to answer this there. Neither am I able to get it now, as to why the output is the way it is.
  Here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Base
  {
  public:
      virtual void fun ( int x = 0)
      {
          cout &lt;&lt; "Base::fun(), x = " &lt;&lt; x &lt;&lt; endl;
      }
  };
  
  class Derived : public Base
  {
  public:
      virtual void fun ( float x = 10.0 )
      {
          cout &lt;&lt; "Derived::fun(), x = " &lt;&lt; x &lt;&lt; endl;
      }
  };
  
  
  int main()
  {
      Derived d1;
      Base *bp = &amp;d1;
      bp-&gt;fun();
      d1.fun();
      d1.fun(1.2);
      return 0;
  }
  </code></pre>
  
  <p>The output of the above code is:</p>
  
  <pre><code>Base::fun(), x = 0
  Derived::fun(), x = 10
  Derived::fun(), x = 1.2
  </code></pre>
  
  <p>The problem is:
  In the first case we say that both the fun() functions get overloaded (and not overridden since they differ in their declarations) and the base fun() gets called, but it is not possible for these declarations of fun() to be overloaded (since they differ only whether the declaration contains default argument or not)</p>
  
  <pre><code>void fun(int x = 0)
  void fun(float x = 10.0)
  </code></pre>
  
  <p>It is not possible for these functions to get overloaded. </p>
  
  <p>There seems to be a contradiction in both the above cases.</p>
  
  <p>Any related article/ link explaining the situation would be highly helpful.</p>