What is Upcasting?
An object can be used as its own type or as an object of its base type. In addition it can be manipulated through an address of the base type. Taking the address of an object (either a pointer or a reference) and treating it as the address of the base type is called upcasting because of the way inheritance trees are drawn with the base of the class at the top.
// code example of Upcasting
class Vehicle
{
public:
Vehicle(){}
Virtual void GetRegistration();
};
class Car : public Vehicle
{
public:
Car(){}
void GetRegistration()
{
cout << "Car, registration: "
}
};
Vehicle* vp1 = new Car(); // Upcasting
C++ FAQ Home