// This class looks fine right?? It compiles so it must be right??

#include <iostream>

class Base {
 public:
  Base()  { std::cout << "Base()"  << std::endl; x = new int; }
  virtual ~Base() { std::cout << "~Base()" << std::endl; delete x; }
  virtual void fn() { std::cout << "Base::fn()" << std::endl; }
private:
  int *x;
};

class D1 : public Base {
 public:
  D1()  { std::cout << "D1()"  << std::endl; y = new int; }
  ~D1() { std::cout << "~D1()" << std::endl; delete y; }
  void fn() { std::cout << "D1::fn()" << std::endl; }
private:
  int *y;
};

int main(int argc, char **argv) {
  Base *b = new Base;
  Base *dptr = (Base *) new D1;

  b->fn();
  dptr->fn();

  delete b;
  delete dptr;

  return 0;
}