Virtual function output?
<p>I was just doing some stuff and wrote this program. I got the following output. I know that function resolution happens at run time while binding of the variable takes place during compile time, but what I could not understand was the first output I got (<code>this-&gt;n</code>). Can anyone explain this to me? </p>

<pre><code>    # include &lt;iostream&gt;
    # include &lt;stdio.h&gt;
    # include &lt;conio.h&gt;

    using namespace std;

    class A
    {
      int n;      
      public:
      virtual void Fun1(int no=10)
       {
         int n=no;        
         cout&lt;&lt;"A::Fun1() "&lt;&lt;n &lt;&lt;"\n";
       }
    };

    class B :public A
    {
     int n;      
     public:
     virtual void Fun1(int no=20)
     {
      int n=no;        
      cout&lt;&lt;"B::Fun1() " &lt;&lt; this-&gt;n &lt;&lt; "\n"; // WHY SO ? gives B::Fun1() 40
      cout&lt;&lt;"B::Fun1() " &lt;&lt; n &lt;&lt; "\n";
     }
    };

    int main()
    {
     B b;
     A &amp;a =b;
     a.Fun1();
     A a1=b;
     a1.Fun1();
     getch();
     return 0;
    }
</code></pre>

<p>The output I got was</p>

<pre><code>    B::Fun1() 40
    B::Fun1() 10
    A::Fun1() 10    
</code></pre>
