-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconstructor in derived class.cpp
68 lines (49 loc) · 1.1 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
#include<iostream>
using namespace std;
class number1{
public:
int a;
int b;
number1(int data1,int data2){
a = data1;
b = data2;
cout<<"constructor first called here"<<endl;
}
void print_number1(){
cout<<"the value of number1 is "<<a<<endl;
cout<<"the value of number1 is "<<b<<endl;
}
};
class number2{
public:
int c;
int d;
number2(int data3, int data4){
c = data3;
d = data4;
cout<<"then here" <<endl;
}
void print_number2(){
cout<<"the value of number2 "<<c<<endl;
cout<<"the value of number2 "<<d<<endl;
}
};
class derived : public number2, public number1{
public:
int der1, der2;
derived(int a, int b, int c, int d, int e, int f) : number1(a,b), number2(c,d){
der1 = e;
der2 = f;
}
void print_derived(){
cout<<"the value of derived is "<<der1<<endl;
cout<<"the value of derived2 is "<<der2<<endl;
}
};
int main(){
derived mangal(1, 2, 3, 4, 5 ,6);
mangal.print_number1();
mangal.print_number2();
mangal.print_derived();
return 0;
};