|
|||||||||||||||||||
|
Section 19:
|
[19.4] Is it OK to convert a pointer from a derived class to its base class?
Yes. An object of a derived class is a kind of the base class. Therefore the conversion from a derived class pointer to a base class pointer is perfectly safe, and happens all the time. For example, if I am pointing at a car, I am in fact pointing at a vehicle, so converting a Car* to a Vehicle* is perfectly safe and normal:
void f(Vehicle* v);
void g(Car* c) { f(c); } // Perfectly safe; no cast
(Note: this FAQ has to do with public inheritance;
private and protected
inheritance are different.)
|
||||||||||||||||||