C++对象模型 ch3 Data语义学

例子,求下面的程序输出。

/home/a/j/nomad2:cat ch3.CPP #include <iostream> using namespace std; class X { }; class Y : public virtual X { /* public: char c; */ }; class Z : public virtual X { /* public: char d; */ }; class A : public Y, public Z { }; int main() { cout << sizeof(X) << endl; cout << sizeof(Y) << endl; cout << sizeof(Z) << endl; cout << sizeof(A) << endl; }
输出如下:

/home/a/j/nomad2:uname -a Linux ubuntu 2.6.24-22-generic #1 SMP Mon Nov 24 19:35:06 UTC 2008 x86_64 GNU/Linux /home/a/j/nomad2:./a.out 1 8 8 16

Each class object, then, is exactly the size necessary to contain the nonstatic data members of its class. This size may at times surprise you as being larger than necessary, as it did my correspondent from France. This girth comes about in two ways:

1. Additional data members added by the compilation system to support some language functionality (primarily the virtuals)

2. Alignment requirements on the data members and data structures as a whole



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值