This code failed to compile with both gcc and Comeau online compiler - the call to f() through a A* pointer in C::g() seems to be invalid and the call with a pointer to C it is valid, but i don't understand why. Could you explain it to me, please?
Code:class A
{
protected:
virtual void f() {}
};
class C : public A
{
public:
void g();
};
void C::g()
{
A* pA = new C();
pA->f(); // not accessible ?
C* pC = new C();
pC->f(); // OK
}
int main()
{
}
