11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

268Part IV: Inheritancevoid VehicleFn(Vehicle& v);void MotorFn(Motor& m);int main(int nNumberofArgs, char* pszArgs[]){Car car;VehicleFn(car); // this is allowedMotorFn(car); // this is not allowedMotorFn(car.motor);// this is, howeverreturn 0;}The call VehicleFn(c) is allowed because car IS_A vehicle. The callMotorFn(car) is not because car is not a Motor, even though it contains aMotor. If the intention was to pass the Motor portion of c to the function, thismust be expressed explicitly, as in the call MotorFn(car.motor).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!