C++  .NET  C#  Java  C  ASP  HTML  Prolog  Visual Basic  Javascript  JScript  VBScript  MFC  Perl  PHP  Basic  Python  C  Assembler  VB  Ada  Ruby  XML  ASP.NET  C++  Java
[warebiz] :: Programming Bizness

Specializing in programming tutorials that make sense!

 Programming Tutorials

 Resources     » Articles
    » Projects
    » CS Dictionary
    » References
    » Books

 Site     » Home
    » About
    » Support
    » Make Donation
binary digits
C++ Ripped Apart Tutorial
Section 9: Object Oriented Programming (OOP) 

You are in Section 9 of 9, Article 9.3 of 9.7

9 .. Object Oriented Programming (OOP)
       9.3 .. Function Overloading


Function Overloading

When using multiple constructors for a class, you are actually overloading functions. Operators and regular non-class functions can also be overloaded.

To overload a regular non-class function, simply create multiple functions using the same function name but with each having a different signature, which is the name, number of parameters, order and types of the parameters, and the class to which it belongs (does not include the return type).

The overloaded functions must have different parameter lists so the compiler knows which function to use depending on the order and types of the arguments.

For example, consider the following overloaded add() function:

Source Code

overloadfuncs.cpp



For another example of overloaded functions, study the following complete program which demonstrates the use of "swap" functions:



Here is a comlete program example:

Source Code

swapfunctions.cpp



This swap( ) function is defined for integers, floating point values (double), and strings. All three may be included in the same program. When the function is called within the program, the compiler will determine which function to use by evaluating the parameter list of the calling function.

Just like functions, certain operators can also be overloaded.

Read on for more...

Next: Operator Overloading

You are in Section 9 of 9, Article 9.3 of 9.7

[Back to Top]

Google
 
Web warebizprogramming.com

.: Report Bug : Error Log : About Webmaster :.

Search Warebiz!
binary digits binary digits

 Random Insight ::

binary digits

 Book References ::

binary digits
 C++  .NET  C#  Java  C  ASP  HTML  Prolog  Visual Basic  Javascript  JScript  VBScript  MFC  Perl  PHP  Basic  Python  C  Assembler  VB  Ada  Ruby  XML  ASP.NET  C++  Java