c++ - Greater than and less than together -
this question has answer here:
- ternary comparison operator overloading 2 answers
i overloading operator > in c++ possible write codes this:
if(a>x>b)...; i have seen operator requires 2 arguments.
any idea how this?
thanks!
this relatively simple example should want:
#include <iostream> struct cool_operator { cool_operator(int _n = 0, bool b = true) : first(b), n(_n) {} bool first; bool operator <(int x) const { return first && (n < x); } int n; }; cool_operator operator <(int x, cool_operator const &rhs) { return cool_operator(lhs.n, x < rhs.n); } int main() { cool_operator c(4); std::cout << std::boolalpha << (3 < c < 5); // true } to make complete, should add member function overloads greater operator, , implement free function overload version of too.
Comments
Post a Comment