fork download
  1. class A{
  2. public:
  3. virtual bool operator<(const A & object) const = 0; // I assume you only care about B and C
  4. };
  5.  
  6. class C;
  7.  
  8. class B: public A{
  9. public:
  10. virtual bool operator<(const A & object) const
  11. {
  12. // do a second bind, now that we know this is type B. Negate cause we
  13. // are switching the operands.
  14. return !object.operator<( (const B&)*this);
  15. }
  16. virtual bool operator<(const B & object) const
  17. {
  18. return true;
  19. }
  20. virtual bool operator<(const C & object) const
  21. {
  22. return true; // B is always < than C right?
  23. }
  24. };
  25.  
  26. class C: public A{
  27. public:
  28. virtual bool operator<(const A & object) const
  29. {
  30. // do a second bind, now that we know this is type C. Negate cause we
  31. // are switching the operands.
  32. return !object.operator<( (const C&)*this);
  33. }
  34. virtual bool operator<(const B & object) const
  35. {
  36. return false; // C is always > then B right?
  37. }
  38. virtual bool operator<(const C & object) const
  39. {
  40. return true;
  41. }
  42. };
  43.  
  44. int main() {
  45. A* a1 = new B();
  46. A* a2 = new C();
  47. bool r = *a1 < *a2;
  48. }
Runtime error #stdin #stdout 0s 11120KB
stdin
Standard input is empty
stdout
Standard output is empty