Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A{
- public:
- void f(){ printf("A.f "); }
- A(){ f(); }
- ~A(){ printf("~A "); }
- };
- class B {
- public:
- void f(){ printf("B.f "); }
- B(){ f(); }
- ~B(){ printf("~B "); }
- };
- class C : public A, public B{
- public:
- C(){ f(); }
- void f(){ printf("C.f "); }
- ~C(){ printf("~C "); }
- };
- int zad4(){
- A*a = new C(); // (1)
- B*b = new C(); // (2)
- delete a; // (3)
- delete b; // (4)
- return 0; // (5)
- }
- /* A.f B.f C.f A.f B.f C.f ~A ~B
- (1) Konstruktor C:
- - konstruktor A (dziedziczenie) - wypisuje A.f A.f
- - konstruktor B (dziedziczenie) - wypisuje B.f B.f
- - konstruktor C - wypisuje C.f C.f
- (2) Konstruktor C:
- - konstruktor A (dziedziczenie) - wypisuje A.f A.f
- - konstruktor B (dziedziczenie) - wypisuje B.f B.f
- - konstruktor C - wypisuje C.f C.f
- (3) Destruktor A - wypisuje ~A ~A
- (4) Destruktor B - wypisuje ~B ~B
- (5) Nic nie wypisuje
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement