-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq47.cpp
46 lines (42 loc) · 1.1 KB
/
q47.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;
class Superparent {
int a;
public:
Superparent(int a) {
cout << "Arguments passed to superparent constructor:\n";
cout << "a = " << a << '\n';
}
~Superparent() {
cout << "Superparent destructor called!\n";
}
};
class Parent : public Superparent {
int b;
public:
Parent(int a, int b) : Superparent(a), b(b) {
cout << "Arguments passed to parent constructor:\n";
cout << "a = " << a << '\n';
cout << "b = " << b << '\n';
}
~Parent() {
cout << "Parent destructor called!\n";
}
};
class Child : public Parent {
int c;
public:
Child(int a, int b, int c) : Parent(a, b), c(c) {
cout << "Arguments passed to child constructor:\n";
cout << "a = " << a << '\n';
cout << "b = " << b << '\n';
cout << "c = " << c << '\n';
}
~Child() {
cout << "Child destructor called!\n";
}
};
int main() {
Child ch(1, 2, 3);
return 0;
}