Upcasting from Derived Class Obect to Base Class Object

Downcasting and Upcasting

Pet vpet;
Dog vdog; //Dog is a derived class with base class Pet.

vdog = static_cast<Dog>(vpet); //ILLEGAL!  DOWNCASTING

However, casting in the other direction is perfectly legal and does not even need a casting operator:

vpet = vdog; //Legal (but does produce the slicing problem.) UPCASTING
Hosted by www.Geocities.ws

1