我正在尝试创建以下子类:
template <
class THandler,
class ThreadModel = CComSingleThreadModel,
class TagReplacerType = CHtmlTagReplacer< THandler >
>
class CRequestHandlerT :
public TagReplacerType,
public CComObjectRootEx< ThreadModel >,
public IRequestHandlerImpl< THandler >
如果按以下方式使用,上述类可以完美运行:
class Cmy_form : public CRequestHandlerT<Cmy_form>
但我正在尝试创建一个子类(通过添加额外的成员函数来扩展CRequestHandlerT功能):
class Cmybase_form : public CRequestHandlerT<Cmybase_form> {...};
class Cmy_form : public Cmybase_form {...}; // builds but runtime error
答案 0 :(得分:1)
我根据自己的理解编写了一些代码并且工作正常。如果我误解了你的要求,请告诉我。
#include <iostream>
using namespace std;
template <class T>
class tbase {
public:
tbase () {}
~tbase () {}
virtual bool my_print (T value)
{
cout << "Value passed is: " << value << endl;
}
virtual void print ()
{
cout << "TBASE" << endl;
}
};
template <class T>
class mbase : public tbase<T>
{
public:
mbase ()
: tbase<T>()
{}
virtual void print ()
{
cout << "MBASE" << endl;
}
};
template <class T>
class child : public mbase <T>
{
public:
child ()
: mbase<T> ()
{}
virtual void print ()
{
cout << "CHILD" << endl;
}
};
int main ()
{
tbase <int> * b = new child<int>;
b->print();
b->my_print( 10 );
return 0;
}
如果不符合您的要求,请退回。我们将努力解决这个问题。