Guest User

Untitled

a guest
Aug 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A{
  5. public:
  6. A() { cout<<"A ctor"<<endl; }
  7. virtual ~A()=0 { cout<<"A dtor"<<endl; }
  8. virtual void f(A*) { cout<<"A's f"<<endl; }
  9. };
  10.  
  11. class B: public A{
  12. public:
  13. B():A() { cout<<"B ctor"<<endl; }
  14. virtual ~B() { cout<<"B dtor"<<endl; }
  15.  
  16. virtual void f(A*) {cout<<"B's f"<<endl;}
  17. };
  18.  
  19. class C: public A{
  20. public:
  21. C():A() { cout<<"C ctor"<<endl; }
  22. virtual void f(A*) {cout<<"C's f"<<endl;}
  23. virtual ~C() { cout<<"C dtor"<<endl; }
  24. };
  25.  
  26. int main()
  27. {
  28. //A *ap= new A(); - compilation error
  29. A *bp= new B();
  30. A *cp= new C();
  31.  
  32. bp->f(cp);
  33.  
  34. delete bp;
  35. delete cp;
  36.  
  37. return 0;
  38. }
  39.  
  40. OUTPUT:
  41.  
  42. A ctor
  43. B ctor
  44. A ctor
  45. C ctor
  46. B's f
  47. B dtor
  48. A dtor
  49. C dtor
  50. A dtor
Add Comment
Please, Sign In to add comment