Overload Resolution in C++

Discussion in 'C++' started by zbigniew@szymczyk.eu, Oct 29, 2008.

  1. Guest

    Can someone explain me how overload resolution works in C++?

    For example if I have function void f(char, int); and I will call
    f('A', 3.1) or f(1.5, 3.1F) what would be the result?

    Thanks
    , Oct 29, 2008
    #1
    1. Advertising

  2. asterisc Guest

    On Oct 29, 3:06 pm, Victor Bazarov <> wrote:
    > wrote:
    > > Can someone explain me how overload resolution works in C++?

    >
    > > For example if I have function void f(char, int); and I will call
    > > f('A', 3.1) or f(1.5, 3.1F) what would be the result?

    >
    > If you only have a single function called 'f', no overload is present.
    > Overload is only there if you have more than one function named 'f':
    >
    >      void f(char, int);
    >      void f(long, double);
    >
    >      int main() {
    >          f(0L, 0.0); // the latter is called
    >          f('c', 42); // the former is called
    >      }
    >
    > Explaining how overload resolution "works" can take weeks.  Please find
    > a decent C++ book and read the section/chapter on overloading.
    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask


    Indeed. However, there are some rules that are followed, which are not
    that complicated.
    Try looking:
    http://accu.org/index.php/journals/268
    asterisc, Oct 29, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eph0nk

    Error: Overload resolution failed

    Eph0nk, Oct 23, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,860
    Eph0nk
    Oct 23, 2003
  2. =?Utf-8?B?Q2FpbGlu?=
    Replies:
    0
    Views:
    1,592
    =?Utf-8?B?Q2FpbGlu?=
    Sep 9, 2005
  3. Wolfgang Jeltsch

    overload resolution

    Wolfgang Jeltsch, Aug 31, 2003, in forum: C++
    Replies:
    2
    Views:
    404
    Filipe Sousa
    Aug 31, 2003
  4. Piotre Ugrumov
    Replies:
    3
    Views:
    371
    Nick Hounsome
    Jan 25, 2004
  5. Ying-Chieh Liao

    function overload (not operator overload)

    Ying-Chieh Liao, Oct 11, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    251
    Sherm Pendley
    Oct 11, 2004
Loading...

Share This Page