Contents Up << >>

Is it ok to convert a pointer from a derived class to its base class?

Yes.

A derived class is a specialized version of the base class ("Derived is a kind-of Base"). The upward conversion is perfectly safe, and happens all the time (if I am pointing at a car, I am in fact pointing at a vehicle):

  	void f(Vehicle* v);
	void g(Car* c) { f(c); }	//perfectly safe; no cast
Note that the answer to this FAQ assumes we're talking about " public" inheritance; see below on "private/protected" inheritance for "the other kind".