在 C++ 中,我想将一个类转换为另一个类,所以我决定创建一个模板类,但是我遇到了编译错误,这是错误,
"MyFooClass.h", line 10: error (etoa:4997):
function "IFoo::show(OtherClass &)" is hidden by
"MyFooClass::show" -- virtual function override
intended?
virtual std::auto_ptr<ClNewClass> show(ClOldClass &oc)
这是我的代码,
//IFoo.h
class IFoo
{
public:
virtual ~IFoo(){}
protected:
virtual std::auto_ptr<OtherClass> show(OtherClass &oc) = 0;
};
//CustomFoo.h
template<typename oldClass, typename newClass>
class CustomFoo : public IFoo
{
public:
virtual std::auto_ptr<newClass> show(oldClass &oc)=0;
protected:
virtual std::auto_ptr<OtherClass> show(OtherClass &oc)
{
std::auto_ptr<OtherClass> result(show(static_cast<oldClass &>(oc)));
return result;
}
};
//MyFooClass.h
class MyFooClass : public CustomFoo< ClOldClass, ClNewClass >
{
public:
virtual std::auto_ptr<ClNewClass> show(ClOldClass &oc)
{
std::auto_ptr<ClNewClass> cnv(new ClNewClass(oc.params));
return cnv;
}
};
谢谢。