fork download
  1. #include <iostream>
  2.  
  3. class A {
  4. private:
  5. int n;
  6. public:
  7. A(int n) : n(n) {
  8. }
  9. bool operator < (const A *obj) {
  10. if (obj->n < this->n)
  11. return true;
  12. else if (this->n < obj->n)
  13. return false;
  14. }
  15. };
  16.  
  17. int main()
  18. {
  19. A a(4), b(5);
  20. std::cout << ((a < &b) ? "a less than b" : "b less than a") << std::endl;
  21. }
Success #stdin #stdout 0.01s 2680KB
stdin
Standard input is empty
stdout
b less than a