overloading functions

Discussion in 'Mac Programming' started by FuuFuu, Oct 4, 2010.

  1. macrumors regular

    FuuFuu

    Joined:
    Jul 8, 2008
    Location:
    Roselle
    #1
    a simple question. how does a compiler figure out which function to execute when you multiple functions are given the same name(overloading)?


    thanks
     
  2. macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #2
    by argument type
     
  3. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #3
    A function signature consists of the return type, the name, and the number and type of arguments. In most languages when a function is called the return type isn't easily discerned, so generally you can't have two methods with the same name and argument types and a different return type. This means the compiler depends on the name and the number and types of arguments. When a method is being invoked, the compiler can evaluate any expressions passed as arguments and use this information to decide what function will be called.

    -Lee
     

Share This Page