我得到一個編譯錯誤,當我打電話testcomp隔離的構造,其設計如下推導:從一個純虛模板類
template <typename R>
class IComparable
{
public:
virtual bool Equals(const R & rhs) const = 0;
};
class TestComp : IComparable<char*>
{
public:
std::string x;
TestComp(std::string & a)
{
x = a;
}
virtual bool Equals(const char* & a) const
{
return x == std::string(a);
}
};
錯誤:
error C2259: 'TestComp2' : cannot instantiate abstract class due to following members:'bool IComparable<R>::Equals(const R &) const' : is abstract with [ R=char * ]
,我可以不明白,因爲我將TestComp :: Equals定義爲與IComparable :: Equals相似的簽名。
我在嘗試各種解決方法時注意到的一件事是,如果我將兩個函數'Equals(R & rhs)const'從參數中刪除const,那麼我不會再收到此錯誤。
有人可以幫我理解這種行爲嗎?