#include
class base
{
public:
virtual void print (int a)
{
std::cout << \"a: \" << a << \" base\\n\";
}
Overload resolution happens at compile time. Overrides happen at run time.
Therefore, the overload resolution of b->print(d);
happens first. This selects Base::print(int)
because it's the only one-argument print
.
At runtime, b
points to a Derived
object that has no override for Base::print(int)
. Therefore, Base::print(int)
is still called.