Results 1 to 5 of 5

Thread: overload a function

  1. #1
    Contributing Member
    Join Date
    Apr 2007
    Answers
    41

    overload a function

    Hello all,

    Why cant we overload a function with return type in C++?
    We know that compiler wont support, but is there any specific reason for it?

    Thanks,


  2. #2
    Expert Member
    Join Date
    Dec 2006
    Answers
    204

    Re: overload a function

    Overloading can be done by various signatures of a function.
    return type is not the signature.


  3. #3
    Expert Member
    Join Date
    Nov 2006
    Answers
    518

    Re: overload a function

    I agree with Barbie.

    One more reason that comes in my mind is,

    C++ has a feature called auto-conversion of types. If we equate a function output to an int variable that actually returns a float value, we all know that it automatically converts float output to an int and assigns it to the variable.

    With this feature if we overload the functions with different return types, it creates ambiguity.

    Lack of WILL POWER has caused more failure than
    lack of INTELLIGENCE or ABILITY.

    -sutnarcha-

  4. #4
    Contributing Member
    Join Date
    Apr 2007
    Answers
    41

    Re: overload a function

    Thanks dude..
    Ur answer made my doubt clear


  5. #5
    Junior Member
    Join Date
    Feb 2006
    Answers
    8

    Re: overload a function

    C++ mangles the function name in the object file (after it is compiled) with the function's parameter types but not the return type. Therefore, the linker cannot distinguish between functions with the same parameter types but different return types since the object module lacks the information so do that.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact