-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathempty_inheritance_size_test.cc
71 lines (51 loc) · 1.25 KB
/
empty_inheritance_size_test.cc
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
#include <stdio.h>
class Base
{
};
class Left : public Base
{
};
class Right : public Base
{
};
class Third : public Base
{
int a;
};
class Fouth : public Base
{
Third dddd;
int i;
};
class Bottom : public Left, public Right
{
};
class Bottom_bottom : public Bottom
{
};
int main()
{
Base ob;
Bottom obm;
unsigned char judge = *((unsigned char*)&ob);
unsigned char judge_for_obm1 = *((unsigned char*)(&obm));
unsigned char judge_for_obm2 = *((unsigned char*)(&obm) + 1);
printf("%02x\n", judge);
printf("%02x\n", judge_for_obm1);
printf("%02x\n", judge_for_obm2);
printf("the addr of ob is %p\n", &ob);
printf("the addr of obm is %p\n", &obm);
printf("the sizeof Base is %zu\n", sizeof(Base));
printf("the sizeof Left is %zu\n", sizeof(Left));
printf("the sizeof Right is %zu\n", sizeof(Right));
printf("the sizeof Bottom is %zu\n", sizeof(Bottom));
printf("the sizeof Third is %zu\n", sizeof(Third));
printf("the sizeof Fouth is %zu\n", sizeof(Fouth));
printf("the sizeof Bottom_bottom is %zu\n", sizeof(Bottom_bottom));
Left *lp = (Left*)&obm;
Right *rp = (Right*)&obm;
printf("the lp is %p\n", lp);
printf("the rp is %p\n", rp);
//Left *pp = dynamic_cast<Left*>(p);// compile error source type is not polymorphic
return 0;
}