function overloading

s.jeevitha's Avatar, Join Date: Jul 2010
Newbie Member
i want a program codings for function overloading...?can u help me........
bluecoder's Avatar
Go4Expert Member
please pick any c++ book and you will find the code .
rrosario's Avatar, Join Date: Nov 2010
Newbie Member
The idea of overloading is so that the same name for more than one function in a class. Here is an example.

PHP Code:
void Display(const char *theText) const;
void Display(const aRequest &theRequest) const;
void Display(cont float theNumber) const; 
Once defined you can call them
PHP Code:
myExternalInterface.Display("Some text");
myExternalInterface.Display(theRequest);
myExternalInterface.Display(1.5); 
micpayne's Avatar, Join Date: Nov 2010
Newbie Member
Quote:
Originally Posted by s.jeevitha View Post
i want a program codings for function overloading...?can u help me........
In addition to rrosario's excellent example, in laymans terms it allows a function to take an argument of various types or an argument of many parameters and varied types. Take for instance if you had a function called EditContact(). You could invoke it in the following ways (given they are properly defined):
  1. EditContact() //no argument might prompt for everything
  2. EditContact(int phone)
  3. EditContact(string name)
  4. EditContact(int phone, string name)

All the above functions have the same name, but are different because they take different arguments. So using the above as reference:

  • EditContact(5555555555) would call 2 from above.
  • EditContact(5555555555, "Billy Mays") would call 4 from above.

...and etc. Overloading is done behind the scene and the compiler knows which one to use.

~UAT Student