title: Why C++ cannot initialize a variable of type "derived class" with an rvalue of type "super class"?
body: <p>Please consider the code below:</p>
  
  <pre><code>class a
  {
      int a1;
  
      public:
      a()
      {
          printf("foo1\n");
      }
  };
  
  class b : public a
  {
      int a2;
      public:
      b()
      {
          printf("foo2\n");
      }
  };
  int main (int argc, const char * argv[])
  {
      b *instance = new a();
      return 0;
  }
  </code></pre>
  
  <p>It gives Error: Cannot initialize a variable of type "b*" with an rvalue of type "a*"
  Works fine when I write </p>
  
  <pre><code>a *instance = new b();
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>foo1
  foo2
  </code></pre>
  
  <p>Can someone please explain me the reason? I would be extremely grateful :)</p>
  
  <p>Another thing, if I write </p>
  
  <pre><code>instance-&gt;~a();
  </code></pre>
  
  <p>above <code>return 0;</code> nothing extra happens. Is this because a constructor can be called only once?</p>