title: Virtual functions - base class pointer
body: <p>I understood why a base class pointer is made to point to a derived class object. But, I fail to understand why we need to assign to it, a base class object, when it is a base class object by itself. </p>
  
  <p>Can anyone please explain that?</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  class base {
       public:
          virtual void vfunc() {
              cout &lt;&lt; "This is base's vfunc().\n";
           }
  };
   class derived1 : public base {
        public:
              void vfunc() {
                   cout &lt;&lt; "This is derived1's vfunc().\n";
      }
  };
  int main()
  {
       base *p, b;
       derived1 d1;
       // point to base
       p = &amp;b;
       p-&gt;vfunc(); // access base's vfunc()
       // point to derived1
       p = &amp;d1;
       p-&gt;vfunc(); // access derived1's vfunc()
       return 0;
  }
  </code></pre>