From a comment of mine in a previous question :
Since there can't be instances of abstract classes a pure virtual function can never be selected after overload resolution
The obvious response was :
abstract_class* a = new derived_class; a->pure_virtual_function();
and the best proof of correctness saying :
Dynamic dispatch occurs at runtime, based on whichever object is actually being used at that time. Overload resolution occurs at compile time.
Yet what bothers me is that when resolving explicitly the scope of a class member in our case compilation fails, so it looks like a pure virtual function
is never actually selected through overload resolution :
struct B
{
virtual void copy(B const& rhs) = 0;
};
struct D : B
{
void copy(B const& rhs)
{
D const *pd = dynamic_cast<D const*>(&rhs);
if (pd) {
y = pd->y;
}
}
int y;
};
int main()
{
D d1, d2;
d1.y = 2;
d2.y = 5;
B *p1(&d1), *p2(&d2);
////////////////////////////////////////////
(*p1).B::copy(*p2);
////////////////////////////////////////////
return 0;
}
Error message
undefined reference to `B::copy(B const&)'
What's the case here and if the pure virtual function is actually chosen in overload resolution why can't I "force" the compiler to do the same thing (as the resolution does).