C++: Inheritance and Operator Overloading
问题 I have two structs: 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; } }; I would like the following to compile: int main() { Odp<int> odp; odp = 2; Ftw f; f = 2; // C2679: no operator could be found } Is there any way to make this work, or must I define the operator in Ftw as well? 回答1: The problem is that the compiler usually creates an operator= for you (unless