Download presentation
Presentation is loading. Please wait.
1
Function Overloading 03-18-11
2
Overloading Using same name for more than one function Example: ovldmean.cpp
3
Signature Compiler uses signature to tell which function to use. Signature is function name and parameter list. Doesn’t include return type int square (int x); double square (double n); double square(int i);
4
Overloaded Function Useful when details are different depending on data type. Example: ovldmoney.cpp Treats int and double differently
5
Problematic Calls ovldmean1.cpp Ambiguous when argument is int Unclear whether to convert to float or double
6
Polymorphism Using same name to mean different things ACTUALLY NOT QUITE THAT SIMPLE
7
Question Define two versions of an overloaded function, toCm, that converts either yards(which may contain a fractional part) or whole inches. One inch equals 2.54 cm. cm.cpp is a program that needs the functions.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.