-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_circular_pointer_risk.cpp
97 lines (69 loc) · 2.05 KB
/
1_circular_pointer_risk.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
#include <iostream>
#include <memory>
class grandpa{
public:
virtual ~grandpa() {};
virtual void sendtrigger(const int param1, double num) const = 0;
};
class father1 : public grandpa{
public:
father1() : grandpa() {}
virtual ~father1() {}
void sendtrigger(const int param1, double num) const override {
this->Check(param1, num);
}
protected:
void Check(const int param1, double num) const {
std::cout<<"now excuting father1 class :::Check()"<<std::endl;
};
bool update(const int param1);
};
class father2 : public grandpa {
public:
father2(std::shared_ptr<grandpa>base_check) : grandpa(), base_checker(base_check) {}
~father2() {}
void sendtrigger(const int param1, double num) const override {
return this->base_checker->sendtrigger(param1, num);
}
private:
std::shared_ptr<grandpa>base_checker;
};
class son1 : public father2 {
public:
son1(std::shared_ptr<grandpa>base_check) : father2(base_check) {}
~son1() {}
void sendtrigger(const int param1, double num) const override {
father2::sendtrigger(param1, num);
this->Check(param1, num);
}
protected:
void Check(const int param2, double num2) const {
std::cout<<"now excuting son1 class ::::Check()"<<std::endl;
};
bool update();
};
class son2 : public father2 {
public:
son2(std::shared_ptr<grandpa>base_check) : father2(base_check) {}
~son2() {}
void sendtrigger(const int param1, double num) const override {
father2::sendtrigger(param1, num);
this->Check(param1, num);
}
protected:
void Check(const int numa, double numb) const {
std::cout<<"now excuting son2 class ::::Check()"<<std::endl;
};
void update();
};
int main() {
std::shared_ptr<grandpa> base_1 = std::make_shared<father1>();
std::shared_ptr<grandpa> base_2 = std::make_shared<father2>(base_1);
std::shared_ptr<grandpa> base_3 = std::make_shared<son1>(base_2);
std::shared_ptr<grandpa> base_4 = std::make_shared<son2>(base_3);
const int a = 5;
double b = 7;
base_4->sendtrigger(a, b);
std::cout << "hello world" << std::endl;
return 0;
}