You have two options: either put the virtual disk method () in the Car Car definition, or point the Car pointers to the Ford pointers. Most likely, you will want to do the first.
class Car { public: Car(); virtual void drive() {
Now you can drive () your car! You can also make disk () a pure virtual function, for example:
class Car { public: Car(); virtual void drive() = 0; };
This basically means that there is no default implementation for disk (): it MUST be overridden in a subclass. The second method that I mentioned, which, again, you probably do not want, but should be included for completeness, is to overlay the pointer:
static_cast<Ford*>(cars.back())->drive();
This only works if you know in advance that the car is a Ford, but there is little use in this scenario. You can also look at dynamic_cast.
source share