Presentation is loading. Please wait.

Presentation is loading. Please wait.

Function Overloading 03-18-11. Overloading  Using same name for more than one function  Example: ovldmean.cpp.

Similar presentations


Presentation on theme: "Function Overloading 03-18-11. Overloading  Using same name for more than one function  Example: ovldmean.cpp."— Presentation transcript:

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.


Download ppt "Function Overloading 03-18-11. Overloading  Using same name for more than one function  Example: ovldmean.cpp."

Similar presentations


Ads by Google