title: Function definition with default value (c++)
body: <p>Consider the following class:</p>
  <pre><code>class A{
  public:
      void fun(int i=0) {cout&lt;&lt;&quot;Base::fun(&quot;&lt;&lt;i&lt;&lt;&quot;)&quot;;}
  };
  </code></pre>
  <p>If I understand correctly, when the compiler sees <code>void fun(int i=0)</code>, it will define 2 functions for us. One is the function:</p>
  <pre><code>void fun() {cout&lt;&lt;&quot;Base::fun(&quot;&lt;&lt;0&lt;&lt;&quot;)&quot;;}
  </code></pre>
  <p>And the other one is the function:</p>
  <pre><code> void fun(int i) {cout&lt;&lt;&quot;Base::fun(&quot;&lt;&lt;i&lt;&lt;&quot;)&quot;;}
  </code></pre>
  <p>Next, as I understand, we cannot define 2 functions with the same name in a class. For example:</p>
  <pre><code>class A{
  public:
      void fun() {cout&lt;&lt;&quot;Base::fun()&quot;;}
      void fun() {cout&lt;&lt;&quot;Base::fun(&quot;&lt;&lt;0&lt;&lt;&quot;)&quot;;}
  };
  </code></pre>
  <p>does not compile and returns error:</p>
  <pre><code>error: 'void A::fun()' cannot be overloaded with 'void A::fun()'
  </code></pre>
  <p>So, my question is why does the following definition compiles :</p>
  <pre><code>class A{
  public:
      void fun() {cout&lt;&lt;&quot;Base::fun()&quot;;}
      void fun(int i=0) {cout&lt;&lt;&quot;Base::fun(&quot;&lt;&lt;i&lt;&lt;&quot;)&quot;;}
  };
  </code></pre>
  <p>Thanks in advance.</p>