Overloading operator, why does it keep prompting error “operator> has invalid parameters count”?
-
Operator> compares the current object to something else. Therefor one parameter.
bool operator>(const bar_all &that) const{ return this.value > that.value; }
-
Alternatively, define a stand-alone function (not a class method) that takes two arguments.
-
Generally you only need to define operator< and operator== and then
// doesn't compile with 1154 Jun/15 // '>' - semicolon expected // 'const' - name expected // '}' - expressions are not allowed on a global scope // #1255686 | 2015.07.08 21:05 // Operator Overloading can't be standalone functions // Service Desk: We do not support overriding global operators yet template <typename T> bool operator>(const T& lhs, const T& rhs){ return rhs < lhs; } template <typename T> bool operator<=(const T& lhs, const T& rhs){ return !(rhs < lhs); } template <typename T> bool operator>=(const T& lhs, const T& rhs){ return !(lhs < rhs); } template <typename T> bool operator!=(const T& lhs, const T& rhs){ return !(lhs == rhs); }
Where is the error in this code? Thank you!