我有两个结构体:
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
中定义运算符?
operator =
接受 const 引用参数... 将T operator=(const T rhs)
改为T operator=(const T& rhs)
会更好。 - a1ex07