00 /*
01  * inheritance1.cpp
02  *
03  *      Author: Kurt Nørmark / Simonas Saltenis
04  *
05  *      Illustrates constructors and destructors in a hierarchy: the order of their calls, as well as implicit call of default constructors
06  */
07 
08 #include <iostream>
09 #include <string>
10 
11 using namespace std;
12 
13 class Base1
14 {
15 	int i;
16 
17 public:
18 	Base1(int a): i{a}
19 	{ cout << "Base1 constructor" << endl; };
20 
21 	~Base1()
22     { cout << "Base1 destructor" << endl;  };
23 };
24 
25 class Base2
26 {
27 	bool j;
28 
29 public:
30 	Base2(): j{false}     // a default constructor
31 	{ cout << "Base2 default constructor" << endl; };
32 
33 	Base2(bool b): j(b)
34 	{ cout << "Base2 constructor" << endl; };
35 
36 	~Base2()
37 	{ cout << "Base2 destructor" << endl;  };
38 
39 };
40 
41 class Derived: public Base1, public Base2
42 {
43 	double d;
44 public:
45 
46 	Derived(int i, double b):
47 		Base1{i},              // The Base2 constructor is not activated explictly here.
48 		d{b}                   //   ... The default constructor in Base2 is activated implicitly.
49 	{ cout << "Derived constructor" << endl; };
50 
51 	~Derived()
52 	{ cout << "Derived destructor" << endl;  };
53 };
54 
55 int main()
56 {
57 	Derived d1{1, 1.0};
58 }
59 
60 
61