
Object Slicing 629
Explanation: In the above program, the base class A con-
tains one virtual function joy(). In the derived class B,
the function joy() is redefined and defines a new virtual
function joy2(). Figure 15.7 shows VTABLES created
for the base and derived class.
a2->joy2();
The above statement will generate an error message. In the
above statement, the pointer a2 is treated as only a point-
er to the base class object. The function joy2() is not
a member of base class A. Hence, it is not allowed to invoke the function joy2() using the
pointer object a2. However, an address of the derived class is assigned to the base class pointer ...