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

Standard output is empty