-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut48.cpp
84 lines (75 loc) · 1.69 KB
/
tut48.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<iostream>
using namespace std;
void name(){
cout<<'Author: Varun Gupta'<<endl;
}
/*
Case 1:
class A:public B{};
order of execution of constructor ---> A()--->B();
Case 2:
class A: public B, public C{};
Order of execution of constructor --->B()--->C()--->A();
Case 3:
class A: public B, virtual public C{};
order of execution of constructor --->C()--->B()--->A();
Case 4:
class A: virtual public B,virtual public C{};
Order of execution of constructor ---->B()--->C()--->A();
*/
class Base1
{
protected:
int base1a;
public:
Base1(int b1)
{
base1a=b1;
cout<<"This is from base1 class Constructor "<<endl;
}
void print ()
{
cout<<"The base1 value is :"<<base1a<<endl;
}
};
class Base2
{
protected:
int base2a;
public:
Base2(int b1)
{
base2a=b1;
cout<<"This is from base2 class constructor :"<<endl;
}
void print_base2()
{
cout<<"The base2 value is :"<<base2a<<endl;
}
};
class Derived :public Base1, public Base2
{
private:
int der1,der2;
public:
Derived(int a,int b,int c,int d):Base1(a),Base2(b)
{
der1=c;
der2=d;
cout<<"This is from Derived class constructor :"<<endl;
}
void print_Derived()
{
cout<<"The value of der1 and der2 are :"<<endl
<<der1<<endl
<<der2<<endl;
}
};
int main(){
name();
Derived d(1,2,3,4);
d.print();
d.print_base2();
d.print_Derived();
return 0;
}