作者cassey (惡魔凱西)
看板C_and_CPP
標題[問題] C++ 繼承 的問題
時間Tue Jan 4 02:36:50 2011
程式碼:
http://paste.plurk.com/show/346938
問題:
有高手能夠教一下這個 sizeof 的結果是怎麼算的嗎?
我從一開始的
class x
{
public:
float x;
short b;
int c;
}
答案就算不對了,明明是 4 + 2 + 4
可是 print 出來的卻是 12
更不用說後面的繼承問題了
這真的是想破頭也不知道是哪裡關念不對
煩請高手解惑一下 Orz
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.37.83.161
推 dendrobium:google "Data structure alignment" 01/04 02:44
→ wawi:compiler會幫你的short補成4 bytes 01/04 12:25
推 clarkman:offsetof去算 01/04 12:41