How can I call the overrided methods of a specific object?
Lets say I have a typical hierarchy like this:
What I want is to have a specific move() implementation for every class.
So if I have the next code:
List<Vehicle> vehicles = GetVehicles();
foreach (Vehicle v in vehicles)
{
v.move();
}
The call to has to be made to the corresponding move() implementation
depending on the class of v in runtime
I tried with virtual and override but if I call move() in a RedCar
instance, it jumps to Car.move() (I guess this is because is the next
override under Vehicle)
Any clue how can be done?
No comments:
Post a Comment