模版继承

#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;
 return 0;
}

Size of object Point is = 8

#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;
 CPoint3D<int> objPoint3D;
 cout << "Size of object Point3D is = " << sizeof(objPoint3D) << endl;
 return 0;
}

Size of object Point3D is = 12

posted @ 2012-07-19 19:58  byfei  阅读(124)  评论(0编辑  收藏  举报