-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht14.cpp
More file actions
85 lines (68 loc) · 1.5 KB
/
Copy patht14.cpp
File metadata and controls
85 lines (68 loc) · 1.5 KB
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
85
/*---------------------constructor in derived class------------
case1:
class b:public a{
//order of execution of constructor ---first a
};
case2:
class a:public b,public c{
//order of execution of constructor ---first b
};
case3:
class a:public b,virtual public c{
//order of execution of constructor ---first cthan b than a
};
*/
#include <iostream>
using namespace std;
class base1
{
int data1;
public:
base1(int i)
{
data1 = i;
cout << "base 1 class constructor called" << endl;
}
void printdata1()
{
cout << "the value of data 1 is" << data1 << endl;
}
};
class base2
{
int data2;
public:
base2(int i)
{
data2 = i;
cout << "base 2 class constructor called" << endl;
}
void printdata2()
{
cout << "the value of data 2 is" << data2 << endl;
}
};
class derived : public base1, public base2//first base1 will called
{
int derived1, derived2;
public:
derived(int a, int b, int c, int d) : base1(a), base2(b)
{
derived1 = c;
derived2 = d;
cout << "derived class constructr called" << endl;
}
void printderived()
{
cout << "the value of derived1 is" << derived1 << endl;
cout << "the value of derived2 is" << derived2 << endl;
}
};
int main()
{
derived durva(1, 2, 3, 4);
durva.printdata1();
durva.printdata2();
durva.printderived();
return 0;
}