Suppose:
struct A {
virtual int foo(const A& a) const { return 1; }
};
struct B : A {
virtual int foo(const A& a) const { return 2; }
virtual int foo(const B& b) const { return 3; }
};
void testOverloadingBinding(const A& a,const B& b) {
cout << a.foo(b);
}
int main() {
testOverloadingBinding(B(),B());
}
It prints 2. I would assume it prints 3 since this binding is dynamic, and as far as I know overloading has static binding.
Can anyone please explain how the compiler decides which function to invoke here?
This:
is not an override for this:
Therefore it can never be called via a reference to an
A.