c++ - Greater than and less than together -


this question has answer here:

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 } 

here demo.

to make complete, should add member function overloads greater operator, , implement free function overload version of too.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -