给定下面的代码示例,为什么在实现重载的纯抽象方法中,重载AbstractBaseClass::DoAThing( const char* )
作为继承方法不可见?SomeEndClass
DoAThing( const char* const* )
class AbstractBaseClass
{
public:
virtual void DoAThing( const char* withThis ) {}
virtual void DoAThing( const char* const* withThat ) = 0;
AbstractBaseClass() {}
virtual ~AbstractBaseClass() {}
};
class SomeMiddlewareClass : public AbstractBaseClass
{
public:
void ThisIsCool() {}
SomeMiddlewareClass() {}
virtual ~SomeMiddlewareClass() {}
};
class SomeEndClass : public SomeMiddlewareClass
{
public:
void DoAThing( const char* const* withThat ) {}
SomeEndClass() {}
virtual ~SomeEndClass() {}
};
void SomeFunction()
{
SomeEndClass* myClass = new SomeEndClass();
myClass->DoAThing( "withThis" );
((SomeMiddlewareClass*)myClass)->DoAThing( "withThisToo" );
delete myClass;
}
当行被接受时,编译器(和索引器)会在该myClass->DoAThing( "withThis" );
行上产生以下错误。((SomeMiddlewareClass*)myClass)->DoAThing( "withThisToo" );
无效参数 ' 候选者是:void DoAThing(const char * const *)
没有匹配函数调用 'SomeEndClass::DoAThing(const char [9])'</p>
不应该SomeEndClass
继承AbstractBaseClass::DoAThing( const char* )
实现吗?我究竟做错了什么?