-
Notifications
You must be signed in to change notification settings - Fork 0
/
abc.cpp
100 lines (67 loc) · 1.42 KB
/
abc.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
#include "abc.h"
class A::Private
{
public:
virtual ~Private()
{
std::printf("%s %p\n", __PRETTY_FUNCTION__, this);
}
int value;
};
DEFINE_PRIVATE(A)
A::A(const int value)
{
Private & p = to_private();
p.value = value;
std::printf("%s class=%p private=%p\n", __PRETTY_FUNCTION__, this, &p);
}
A::~A()
{
std::printf("%s %p\n", __PRETTY_FUNCTION__, this);
std::fflush(stdout);
}
int A::value() const
{
const Private & p = to_private();
std::printf("%s class=%p private=%p addr(value)=%p\n", __PRETTY_FUNCTION__, this, &p, &p.value);
return p.value;
}
void A::setValue(const int value)
{
std::printf("%s %p\n", __PRETTY_FUNCTION__, this);
Private & p = to_private();
p.value = value;
}
class B::Private : public A::Private
{
public:
~Private() override
{
std::printf("%s %p\n", __PRETTY_FUNCTION__, this);
}
int data;
char foo[15];
};
DEFINE_PRIVATE(B)
B::B(const int data)
{
Private & p = to_private();
p.data = data;
std::printf("%s class=%p private=%p\n", __PRETTY_FUNCTION__, this, &p);
}
B::~B()
{
std::printf("%s %p\n", __PRETTY_FUNCTION__, this);
std::fflush(stdout);
}
int B::data() const
{
const Private & p = to_private();
std::printf("%s class=%p private=%p addr(data)=%p addr(foo)=%p\n", __PRETTY_FUNCTION__, this, &p, &p.data, &p.foo);
return p.data;
}
void B::event(const int what)
{
std::printf("%s %p %d\n", __PRETTY_FUNCTION__, this, what);
to_private().value = what + 100;
}