(no title)
lmitchell | 8 years ago
class Vehicle {
virtual void Collide(Vehicle other);
}
class Car {
void Collide(Truck other) { /* hit a truck */ }
void Collide(Car other) { /* hit another car */ }
}
class Truck {
void Collide(Truck other) { /* hit another truck */ }
void Collide(Car other) { /* hit a car */ }
}
Vehicle c = Car();
Vehicle t = Truck();
c.Collide(t); // with multiple dispatch, calls Car::Collide(Truck)
seanmcdirmid|8 years ago
Multiple dispatch is typically meant to be purely dynamic in meaning, as wiki puts it:
> Multiple dispatch or multimethods is a feature of some programming languages in which a function or method can be dynamically dispatched based on the run-time (dynamic) type or, in the more general case some other attribute, of more than one of its arguments.[1]
(https://en.wikipedia.org/wiki/Multiple_dispatch)
yorwba|8 years ago