Written some cool source code? Upload it to Programmer's Heaven.
*/

Other Views

corner
*/

CPLUSPLUS FAQ - What is Upcasting

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
corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.
Resource Listings