Class A{public:void Funca () { printf ("Funca called\n");} virtual void Funcb () { printf ("FUNCB called\n");} };class b:public a{public:void Funca () { A::funca (); printf ("Funcab called\n"); } virtual void Funcb () { printf ("FUNCBB called\n");}; void Main (void) {b b; A *pa; pa = &b; A *pa2 = new A; Pa->funca (); (3) PA->FUNCB (); (4) Pa2->funca (); (5) PA2->FUNCB (); Delete PA2;}
The parent class pointer points to the subclass instance object, and the function in the parent class is called when the normal override function is called. When you call a quilt class to override a virtual function, the function in the subclass is called. Again, the overridden virtual function in a subclass is dynamically bound, independent of the pointer type of the parent class that currently points to the class instance, and is only relevant to the class instance object itself.
Function call when the parent pointer points to a child class object