I have a class, let's call it Foo, which contains the 3 following methods (overloading the left-associative < binary operator):
... operator<(A a) { return *this; }
... operator<(B b) { return *this; }
... operator<(C c) { return *this; }
A, B, C classes are not related in any way(if that, is of any matter).
Now In my program I only have the 2 following cases:
A a = new A();
B b = new B();
C c = new C();
(First Case): new Foo() < a < b;
or
(Second Case): new Foo() < a < b < c;
Whenever I have the first case (which ends with b
), I want to execute a function run() when I have read(I know) the b instance. So the idea is that I would have the following code in the Foo class:
... operator<(B b)
{
run();
}
Now when I have the code of the first case, run()
is being executed.
The problem is that when I have code like in the second case(which ends in c
).
I want to execute the run()
function again but NOT until I know what c
is.
So If I have the previous piece of code run()
will be called when doing < b
which is not what I want as I don't know c
yet.
If I add run()
in operator<(C c)
I will call run()
twice.
In a few words what I want to accomplish is when having the first case call run()
at operator<(B b)
and when I have the second case ONLY call run at operator<(C c)
.
Any ideas on how this can be solved(if it can)?