Overloaded Expression - Rules in Function Overloading

Rules in Function Overloading

  • The overloaded function must differ either by the arity or data types.
  • The same function name is used for various instances of function call.

It is a classification of static polymorphism in which a function call is resolved using the 'best match technique ', i.e., the function is resolved depending upon the argument list. Method overloading is usually associated with statically-typed programming languages which enforce type checking in function calls. When overloading a method, you are really just making a number of different methods that happen to have the same name. It is resolved at compile time which of these methods are used.

Method overloading should not be confused with forms of polymorphism where the correct method is chosen at runtime, e.g. through virtual functions, instead of statically.

Example: function overloading in c++

main { cout<In the above example, the volume of various components are calculated using the same function call "volume", with arguments differing in their data type or their number.

Read more about this topic:  Overloaded Expression

Famous quotes containing the words rules and/or function:

    However patriarchal the world, at home the child knows that his mother is the source of all power. The hand that rocks the cradle rules his world. . . . The son never forgets that he owes his life to his mother, not just the creation of it but the maintenance of it, and that he owes her a debt he cannot conceivably repay, but which she may call in at any time.
    Frank Pittman (20th century)

    The information links are like nerves that pervade and help to animate the human organism. The sensors and monitors are analogous to the human senses that put us in touch with the world. Data bases correspond to memory; the information processors perform the function of human reasoning and comprehension. Once the postmodern infrastructure is reasonably integrated, it will greatly exceed human intelligence in reach, acuity, capacity, and precision.
    Albert Borgman, U.S. educator, author. Crossing the Postmodern Divide, ch. 4, University of Chicago Press (1992)