title: How is the inheritance working here?
body: <p>I dont know for sure how the code works. How <em>A</em> c0 = new C();* even work? How can I make a pointer 'A' object from a 'C'?</p>
  
  <pre><code>class A {
  public:
      A() { print("Constructor of A"); }
      virtual ~A() { print("Destructor of A"); }
  };
  
  class B : public A {
  public:
      B() { print("Constructor of B"); }
      ~B() { print("Destructor of B"); }
  };
  
  class C : public B {
  public:
      C() { print("Constructor of C"); }
      ~C() { print("Destructor of C"); }
  };
  
  int main() {
      print("A* = C");
      A* c0 = new C();
      delete c0;
  
      print("B* = C");
      B* c1 = new C();
      delete c1;
  
      print("C* = C");
      C* c2 = new C();
      delete c2;
  
      return 0;
  }
  </code></pre>
  
  <p>I thought I understood the inheritance a long time ago but now when I needed to use it I just got lost in the code.</p>