function overloading

Discussion in 'C' started by s.jeevitha, Jul 8, 2010.

  1. s.jeevitha

    s.jeevitha New Member

    Joined:
    Jul 8, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    i want a program codings for function overloading...?can u help me........:thinking::thinking:
     
  2. bluecoder

    bluecoder New Member

    Joined:
    Mar 11, 2010
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    please pick any c++ book and you will find the code .
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
  4. rrosario

    rrosario New Member

    Joined:
    Oct 31, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    The idea of overloading is so that the same name for more than one function in a class. Here is an example.

    PHP:
    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:
    myExternalInterface.Display("Some text");
    myExternalInterface.Display(theRequest);
    myExternalInterface.Display(1.5);
     
  5. micpayne

    micpayne New Member

    Joined:
    Nov 1, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice