类的字节对齐

 1 /* 继承中的类大小 */
 2 
 3 #include<iostream>
 4 
 5 using namespace std;
 6 
 7 class A
 8 {
 9     int num;
10 };
11 
12 class B : public A
13 {
14     double db;
15 };
16 
17 class C : public B
18 {
19     double db;
20 };
21 
22 class my : public A, public B, public C
23 {
24 };
25 
26 // 空类1字节表示自己存在 空类的继承也是一个字节
27 
28 // 继承 等价于类的内部包含了一个父类的对象
29 
30 void main()
31 {
32     cout << sizeof(A) << endl;// 1
33     
34     cout << sizeof(B) << endl;// 16
35 
36     cout << sizeof(C) << endl;// 24
37 
38     cout << sizeof(my) << endl;// 48
39 
40 
41     cin.get();
42 }

 

posted on 2015-06-09 10:22  Dragon-wuxl  阅读(184)  评论(0)    收藏  举报

导航