扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
#include <iostream> using namespace std; class Class { }; int main() { Class objClass; cout << "Size of object is = " << sizeof(objClass) << endl; cout << "Address of object is = " << &objClass << endl; return 0; } |
Size of object is = 1 Address of object is = 0012FF7C |
#include <iostream> using namespace std; template <typename T> class CPoint { public: T m_x; T m_y; }; int main() { CPoint<int> objPoint; cout << "Size of object is = " << sizeof(objPoint) << endl; cout << "Address of object is = " << &objPoint << endl; return 0; } |
Size of object is = 8 Address of object is = 0012FF78 |
#include <iostream> using namespace std; template <typename T> class CPoint { public: T m_x; T m_y; }; template <typename T> class CPoint3D : public CPoint<T> { public: T m_z; }; int main() { CPoint<int> objPoint; cout << "Size of object Point is = " << sizeof(objPoint) << endl; cout << "Address of object Point is = " << &objPoint << endl; CPoint3D<int> objPoint3D; cout << "Size of object Point3D is = " << sizeof(objPoint3D) << endl; cout << "Address of object Point3D is = " << &objPoint3D << endl; return 0; } |
Size of object Point is = 8 Address of object Point is = 0012FF78 Size of object Point3D is = 12 Address of object Point3D is = 0012FF6C |
#include <iostream> using namespace std; class Class { public: virtual void fun() { cout << "Class::fun" << endl; } }; int main() { Class objClass; cout << "Size of Class = " << sizeof(objClass) << endl; cout << "Address of Class = " << &objClass << endl; return 0; } |
Size of Class = 4 Address of Class = 0012FF7C |
#include <iostream> using namespace std; class Class { public: virtual void fun1() { cout << "Class::fun1" << endl; } virtual void fun2() { cout << "Class::fun2" << endl; } virtual void fun3() { cout << "Class::fun3" << endl; } }; int main() { Class objClass; cout << "Size of Class = " << sizeof(objClass) << endl; cout << "Address of Class = " << &objClass << endl; return 0; } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。