C++????????????С
???????????? ???????[ 2012/10/17 10:50:26 ] ????????
?????????????????????????C++??????????NB?????ó?????????The Semantics of Data??????з???????????????????????????????????
???????????class???С??
class X{};
class Y : public virtual X{};
class Z : public virtual X{};
class A : public Y?? public Z{};
??????й?????????
???????????????????????С???????0???????????????κ???????????????????????й????????????????class x?????0???????????С???????????????????vs2010?????2?????С???????????????????????С????????
cout<<"sizeof X: " <<sizeof X<<endl
<<"sizeof Y: " <<sizeof Y<<endl
<<"sizeof Z: " <<sizeof Z<<endl
<<"sizeof A: " <<sizeof A<<endl;
???????????????????????????????class????????????????????????1 byte????????????????????char??????????????????????????е??С???????????????????????£????磺
X xa??xb;
if (&xa == &xb)
cout<<"is equal"<<endl;
else
cout<<"not equal"<<endl;
???????????????????Y??Z???С???????С??????????????
?????? ????????????????????????????????????????????????????????????????????????????洢????????????????????????????
?????? ??????????????????????????????????class X??1 byte???С??????????????class Y??class Z?????????????????????????????Щ???????1byte??????Щ???????????????????????????????????????1byte??????????????е??????λ????
?????? Alignment???????????ν???????????????????????5bytes????????????Ч?????????д??????????8byte??
?????????????vs2010?е??????????????????????1byte???????????class Y??class Z???С??4bytes?????????
?????????????class A???С????????????????????????????????????д????????壬??????????????г??????Σ???????????1byte??classX??壬????? class Y??class Z??????9bytes??????ж???????12bytes????vs2010?????????1byte?????????????????8bytes??????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11