【发布时间】:2010-08-04 23:34:50
【问题描述】:
我有两个结构:
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)
标签: c++ inheritance operator-overloading