标签:
需要补充。。
1. 注意虚函数的指针占4个字节。(当然是32位机器)
#include <cstdlib> #include <ctime> #include <iostream> #include <string.h> using namespace std; class A { public: const int a; }; class B { }; class C { public: ~C() {} }; class D : public C { public: ~D() {} }; class E { public: void print() {}; }; class F : public E { public: void print() {}; }; class G { public: virtual void print() {}; }; class H : public G { public: void print() {}; }; int main() { cout << "sizeof(A) = " << sizeof(A) << endl; // 4 cout << "sizeof(B) = " << sizeof(B) << endl; // 1 cout << "sizeof(C) = " << sizeof(C) << endl; // 1 cout << "sizeof(D) = " << sizeof(D) << endl; // 1 cout << "sizeof(E) = " << sizeof(E) << endl; // 1 cout << "sizeof(F) = " << sizeof(F) << endl; // 1 cout << "sizeof(G) = " << sizeof(G) << endl; // 8 cout << "sizeof(H) = " << sizeof(H) << endl; // 8 return 0; }
标签:
原文地址:http://www.cnblogs.com/lovers/p/4721891.html