T
Tony Johansson
Hello Experts!!
Assume we have the following inheritance tree.
At the top we have the class Vehicle class and the subclass to vehicle is a
class called Engine_vehicle and
below this class we have three subclasses which are Car, Bus and Truck.
If I have a pointer variable to a base class Vehicle like this
Vehicle *vehicle_ptr;
If I now want to check if vehicle_ptr only point to an object of class
Engine_vehicle and only that class.
What happen with the value mp below if vehicle_ptr really points to a
subclass to Engine_vehicle for example Car?
I only want to use dynamic_cast and not typeid.
Engine_vehicle *mp;
if (mp = dynamic_cast<Engine_vehicle *>(vehicle_ptr)
{
//When I'm here I want to be sure that vehicle_ptr really points to an
object of class Engine_vehicle.
}
Many thanks
//Tony
Assume we have the following inheritance tree.
At the top we have the class Vehicle class and the subclass to vehicle is a
class called Engine_vehicle and
below this class we have three subclasses which are Car, Bus and Truck.
If I have a pointer variable to a base class Vehicle like this
Vehicle *vehicle_ptr;
If I now want to check if vehicle_ptr only point to an object of class
Engine_vehicle and only that class.
What happen with the value mp below if vehicle_ptr really points to a
subclass to Engine_vehicle for example Car?
I only want to use dynamic_cast and not typeid.
Engine_vehicle *mp;
if (mp = dynamic_cast<Engine_vehicle *>(vehicle_ptr)
{
//When I'm here I want to be sure that vehicle_ptr really points to an
object of class Engine_vehicle.
}
Many thanks
//Tony