title: Dynamic binding inside constructor for virtual Function in C++
body: <p>As per the standard, we know that constructor always go for an early binding of a virtual function inside them because they don't have complete idea the derived class hierarchy downside.</p>
  
  <p>In this case if early binding is used inside my base constructor, I have passed a derived object to a base class pointer which is completely acceptable (an upcasting is done here). If early binding is used the selection of the virtual function should be based on the type of the pointer (which is Base * here) but not the content of the pointer(the object pointed by the pointer because we don't know the exact object being pointed). In that case since the pointer type is Base * we should have invoked only Base class virtual function in both cases. Could some one please clarify this?</p>
  
  <p>I think dynamic binding is used here rather than early binding. Please correct me if my understanding is wrong.</p>
  
  <p>The first line of the output which invokes base is completely fine    </p>
  
  <pre><code>class Base
      {
          public:
          Base(){
              fun();
          }
          Base(Base *p)
          {
              p-&gt;fun();
          }
          virtual void fun()
          {
              cout&lt;&lt;"In Base"&lt;&lt;endl;
          }
      };
  
      class Derived : public Base
      {
          public:
          void fun()
          {
              cout&lt;&lt;"In Derived"&lt;&lt;endl;
          }
      };
  
      int main()
      {
          Derived d;
          Base b(&amp;d);
      }
  </code></pre>
  
  <p>O/P : </p>
  
  <pre><code>In Base
  In Derived
  </code></pre>