1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #include <iostream> #include <stdlib.h> using namespace std; // float 4 bytes / short 2 bytes / int 4 bytes / double 8 bytes class x { public: float x; short b; int c; private: int s; protected: double w; }; class y : private x { public: int m; short k[3]; }; class z : public y { public: short d[4]; }; int main() { x xxx; cout << sizeof(xxx) << endl; y yyy; cout << sizeof(yyy) << endl; z zzz; cout << sizeof(zzz) << endl; system("pause"); return 0; } // 執行結果: // 24 // 40 // 48 |
Direct link: https://paste.plurk.com/show/346938