#include <iostream>
using namespace std;
class CBase
{
public:
CBase(){};
~CBase(){};
void BaseMethod()
{
cout<<"BaseMethod in Base"<<endl;
}
};
class CMath:public CBase
{
public:
CMath(){};
~CMath(){};
void BaseMethod()
{
cout<<"BaseMethod in CMath"<<endl;
}
};
template<class T>
class CComObject:public T
{
public:
CComObject(){};
~CComObject(){};
void CallBaseMethod()
{
T* pT = static_cast<T*>(this);
pT->BaseMethod();
}
};
void main()
{
CComObject<CMath> * pMath = new CComObject<CMath>;
pMath->CallBaseMethod();
delete pMath;
}
ch01 C++类模板的使用
最新推荐文章于 2025-04-09 19:42:28 发布