-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConstructor_in_Derived_class.cpp
82 lines (75 loc) · 1.86 KB
/
Constructor_in_Derived_class.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
//programming for multiple inheritancea and its ambiguty
// author: jaydattpatel
#include<iostream>
using namespace std;
class A
{
private: int x,xx;
public:
A()
{
x = 0; xx = 0;
cout << "A() constructor called" << endl;
}
A(int p, int q)
{
x = p; xx = q;
cout << "A(int,int) constructor called" << endl;
}
virtual void show()
{
cout<<"x : "<<x<<"\txx :"<<xx<<endl;
}
};
class B
{
private: int y,yy;
public:
B()
{
y = 0; yy = 0;
cout << "B() constructor called" << endl;
}
B(int p, int q)
{
y = p; yy = q;
cout << "B(int,int) constructor called" << endl;
}
virtual void show()
{
cout<<"y : "<<y<<"\tyy :"<<yy<<endl;
}
};
class C: public A, public B // Note the order
{
private: int z,zz;
public:
C()
{
z = 0; zz = 0;
cout << "C() constructor called" << endl;
}
C(int p, int q): A(p,q) , B(p,q) //here A(int,int) and B(int,int) constructure also called
{
z = p; zz = q;
cout << "C(int,int) constructor called" << endl;
}
virtual void show()
{
cout<<"z : "<<z<<"\tzz :"<<zz<<endl;
}
};
int main()
{
cout<<"----------------------------------"<<endl;
C C1;
C1.A::show();
C1.B::show();
C1.show();
cout<<"----------------------------------"<<endl;
C C2(5,10);
C2.A::show();
C2.B::show();
C2.show();
return 0;
}