Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   function overloading (http://www.go4expert.com/forums/function-overloading-t22662/)

s.jeevitha 8Jul2010 19:45

function overloading
 
i want a program codings for function overloading...?can u help me........:thinking::thinking:

bluecoder 9Jul2010 10:51

Re: function overloading
 
please pick any c++ book and you will find the code .

xpi0t0s 9Jul2010 15:05

Re: function overloading
 
http://lmgtfy.com/?q=function+overloading

rrosario 1Nov2010 05:31

Re: function overloading
 
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 1Nov2010 21:23

Re: function overloading
 
Quote:

Originally Posted by s.jeevitha (Post 70051)
i want a program codings for function overloading...?can u help me........:thinking::thinking:

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


All times are GMT +5.5. The time now is 12:57.