c++继承之内存对齐

parvinparvin 389 9月14日 发布
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
#include <iostream>
using namespace std;
 
class BaseClass
{
    int v1, v2;
    char v4;
 
public:
    int temp1();
};
 
class DerivedClass : public BaseClass
{
    int v3;
    int *p;
 
public:
    int temp(){}
};
 
int main()
{
    cout<<"Base = "<<sizeof(BaseClass)<<endl;
    cout<<"Derived = "<<sizeof(DerivedClass)<<endl;
 
    return 0;
}
 
/**
Base = 12
Derived = 24
*/

评论
载入中...