Advertisement
Guest User

Untitled

a guest
May 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. class A{
  2. public:
  3.     void f(){ printf("A.f "); }
  4.     A(){ f(); }
  5.     ~A(){ printf("~A "); }
  6. };
  7.  
  8. class B {
  9. public:
  10.     void f(){ printf("B.f "); }
  11.     B(){ f(); }
  12.     ~B(){ printf("~B "); }
  13. };
  14.  
  15. class C : public A, public B{
  16. public:
  17.     C(){ f(); }
  18.     void f(){ printf("C.f "); }
  19.     ~C(){ printf("~C "); }
  20. };
  21.  
  22. int zad4(){
  23.     A*a = new C();   //   (1)
  24.     B*b = new C();   //   (2)
  25.     delete a;        //   (3)
  26.     delete b;        //   (4)
  27.     return 0;        //   (5)
  28. }
  29.  
  30. /*   A.f B.f C.f A.f B.f C.f ~A ~B
  31.  
  32.     (1) Konstruktor C:
  33.         - konstruktor A (dziedziczenie) - wypisuje A.f      A.f
  34.         - konstruktor B (dziedziczenie) - wypisuje B.f      B.f
  35.         - konstruktor C - wypisuje C.f                      C.f
  36.     (2) Konstruktor C:
  37.         - konstruktor A (dziedziczenie) - wypisuje A.f      A.f
  38.         - konstruktor B (dziedziczenie) - wypisuje B.f      B.f
  39.         - konstruktor C - wypisuje C.f                      C.f
  40.     (3) Destruktor A - wypisuje ~A                          ~A
  41.     (4) Destruktor B - wypisuje ~B                          ~B
  42.     (5) Nic nie wypisuje
  43.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement