-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_inheritance.cpp
133 lines (114 loc) · 1.55 KB
/
simple_inheritance.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <iostream>
using namespace std;
class A{
private:
int callA;
void inc(){
callA++;
}
public:
A(){
callA = 0;
}
int getA(){
cout << "getA() function" << endl;
return callA;
}
protected:
void func(int &a){
cout << "A::func()" << endl;
a *= 2;
inc();
}
};
class B{
private:
int callB;
void inc(){
callB++;
}
public:
B(){
callB = 0;
}
int getB(){
cout << "getB() function" << endl;
return callB;
}
protected:
void func(int &a){
cout << "B::func()" << endl;
a *= 3;
inc();
}
};
class C{
private:
int callC;
void inc(){
callC++;
}
public:
C(){
callC = 0;
}
int getC(){
cout <<"getC() function" << endl;
return callC;
}
protected:
void func(int &a){
cout << "getC() function" << endl;
a *= 5;
inc();
}
};
class D:public A, public B, public C{
private:
int val;
public:
D(){
val = 1;
}
int update_val(int new_val){
cout << "in update_val" << endl;
int a = new_val;
while (a%2 == 0){
a = a/2;
A::func(val);
}
while (a%3 == 0){
a = a/3;
B::func(val);
}
while (a%5 == 0){
a = a/5;
C::func(val);
}
}
void check(int);
};
void D::check(int v){
update_val(v);
cout << "value: "<<val << endl;
cout << getA() << endl;
cout << getB() << endl;
cout << getC() << endl;
}
void exp(int nv)
{
int a = nv;
//int val = a % 2;
while (a%2 == 0){
a = a/2;
//val = a%2;
cout << a << endl;
}
}
int main(){
D d_obj;
int new_val = 60;
d_obj.check(new_val);
//exp(new_val);
return 0;
}