Function Overloading - 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:  Function Overloading

Famous quotes containing the words rules and/or function:

    It was one of the rules which above all others made Doctr. Franklin the most amiable man in society, “never to contradict any body.”
    Thomas Jefferson (1743–1826)

    Every boy was supposed to come into the world equipped with a father whose prime function was to be our father and show us how to be men. He can escape us, but we can never escape him. Present or absent, dead or alive, real or imagined, our father is the main man in our masculinity.
    Frank Pittman (20th century)