私は2つの構造体を持っています:
template <typename T>
struct Odp
{
T m_t;
T operator=(const T rhs)
{
return m_t = rhs;
}
};
struct Ftw : public Odp<int>
{
bool operator==(const Ftw& rhs)
{
return m_t == rhs.m_t;
}
};
私は次のようにコンパイルすることを望みます:
int main()
{
Odp<int> odp;
odp = 2;
Ftw f;
f = 2; // C2679: no operator could be found
}
この作業を行う方法はありますか? Ftw
同様に?
回答:
回答№1の22問題は、コンパイラは通常、 operator=
あなたのために(あなたがそれを提供しない限り)、そしてこれは operator=
継承されたものを隠す。あなたは宣言を使ってこれを覆すことができます:
struct Ftw : public Odp<int>
{
using Odp<int>::operator=;
bool operator==(const Ftw& rhs)
{
return m_t == rhs.m_t;
}
};