Date post: | 08-Jan-2017 |
Category: |
Education |
Upload: | learn-by-watch |
View: | 536 times |
Download: | 0 times |
Yogi’s Guide to
C++Yogi’s Guide
toC++
Function Overloading
Yogendra Pal
www.learnbywatch.com | [email protected]
At the end of this tutorial you will be able to • Explain function signature.
• Differentiate functions on the basis of their signature.
• Explain function overloading.
• Identify overloaded functions from a given c++ program.
• Identify which function will execute on a call to overloaded function.
• Identify an ambiguous function call.
• Write overloaded functions in a c++ program.
www.learnbywatch.com | [email protected]
Function Overloading / Function Polymorphism• Polymorphism (बहुरूपता) means having many forms.
• Function polymorphism: A function in many forms.
• The process of creating same named functions is called function overloading.
• Such functions are called overloaded functions.
• In C++ two functions can have same name as long as their signatures are different.
www.learnbywatch.com | [email protected]
Function Signature / Argument List• Argument list of a function defines it’s signature.
• Signature of a function is different if any one of the following is different.• Number of arguments,
• Data Type of arguments and
• Order of arguments.
void setTime( ); void setTime(int hh); void setTime(int hh, double mm);
void setTime(double hh); void setTime(double mm, int hh);
www.learnbywatch.com | [email protected]
Call an overloaded function• void setTime( );
• void setTime(int hh);
• void setTime(int hh, double mm);
• void setTime(double hh);
• void setTime(double mm, int hh);
• setTime(12.5)
• setTime(12.5 , 7)
• setTime()
• setTime(7, 12.5)
• setTime(7)
www.learnbywatch.com | [email protected]
Ambiguous Call• void setTime(int hh, double mm);
• void setTime(double mm, int hh);
• setTime(5, 1.2)
• setTime(4.2, 5)
• setTime(2, 3)
• setTime(2.1, 4.5)
Yogi’s Guide to
C++Yogi’s Guide
toC++
Ask your questionsto learn better
Yogendra Pal
www.learnbywatch.com | [email protected]