蔡諝的窝

博客园 首页 新随笔 联系 订阅 管理

2011年10月11日 #

摘要: 出于网上对struct、union的字节对齐的文章比较多;而讲继承类的sizeof计算比较少,而且往往因为作者不够细心出了一些误导人的错误的原因,写了此篇博客,请大家指正。首先申明继承类的sizeof计算与struct的sizeof计算是不一样的。请看:class A{public: int a1; char a2;};class B:public A{public: char b1; short b2;};struct ST { int a1; char a2; char b1; short b2;};void main(){ B a; cout<<&(a.a1)< 阅读全文
posted @ 2011-10-11 15:58 蔡諝 阅读(1456) 评论(1) 推荐(0)