
Virtual Functions in Derived Classes 627
tion of these functions depends on the address stored in the base class pointer. For example, p
contains the address of object a; the functions of class shopA are invoked. Similarly, for storing
addresses of objects b and c, functions of classB and classC can be invoked.
p = &s; // Address of s is assigned to p
In the above statement, p contains the address of the object s (base class). Therefore, when the
function area() is invoked by the pointer p, VPTR is created from the object s. With the help of
VPTR, VTABLE of the class shop is obtained, and the address of the function area() for class
shop is ...