关于类得数据成员的大小问题。求解。

Code:
  1. # include<iostream>   
  2. using namespace std;   
  3. class A{   
  4.   
  5. public :   
  6. int b;   
  7. void test()   
  8. {   
  9. int j;   
  10. }   
  11. private:   
  12. char c;   
  13. int a;   
  14.   
  15.   
  16. };   
  17.   
  18. int main()   
  19. {   
  20.        
  21.     cout<<sizeof(A)<<endl;   
  22.     }   

为什么是8啊,把char c注释掉结果是4,把int a 注释掉结果是1.但是为什么在一起就是8了。不明白清前辈指教!

posted on 2011-03-31 22:43  ithzhang  阅读(137)  评论(0)    收藏  举报

导航