I am surprised by the behaviour of my code:
I have an instance A of some container class (containings templates). I defined an operator
in the instance A the template T is a class CVar. CVar contains amongs others the members:
1 2
|
void set(string s);
int operator=(CVar& M);
|
I derived a class
1 2 3 4 5 6
|
class MyINT : public CVar{
...
void set(string s);
int operator=(MyINT& M);
...
}
|
Somewhere in my code I call
If A[i] returns a CVar, CVar::set is called.
If A[i] returns a MyINT, MyINT::set is called.
somewhere else I call
If A[i] and A[j] return CVar variables, CVar::operator= is called.
If A[i] and A[j] both return MyINT variables, still CVar::operator= is called (and not MyINT::operator= as I would desire).
Now I understand, that MyINT::set overrides CVar::set but MyINT::operator= does not override CVar::operator= because the parameters are of different type.
Well, both operators could be adressed by the same call A[i]=A[j], but for some reason CVar wins against MyINT.
Is there some way to influence, which of these operators is called?
It works if I use typeid and cast, but that's not a good solution because I've a lot of operators and childs of CVar.
Any ideas?