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