问一个简单的要死的问题,关于简单的模板调用的
#include "stdafx.h"
#include "iostream"
using namespace std;
template<class T>
class CComObject : public T
{
public:
CComObject() { }
~CComObject() { }
void CallBaseMethod()
{
T* pT = static_cast<T *>(this);
pT->BaseMethod();
}
private:
};
class Base
{
public:
Base() { }
~Base() { }
void BaseMethod()
{
cout << "BaseMethod in Base" << endl;
}
};
class Math : public Base
{
public:
Math() { }
~Math(){ }
void BaseMethod()
{
cout << "BaseMethod in Math" << endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
CComObject<Math>* pMath = new CComObject<Math>;
pMath->CallBaseMethod();
delete pMath;
Math *test = new Math;
(static_cast<Base *>(test))->BaseMethod();
return 0;
}