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 in, rules and/or function:

    There are two great rules in life, the one general and the other particular. The first is that every one can in the end get what he wants if he only tries. This is the general rule. The particular rule is that every individual is more or less of an exception to the general rule.
    Samuel Butler (1835–1902)

    Let’s start with the three fundamental Rules of Robotics.... We have: one, a robot may not injure a human being, or, through inaction, allow a human being to come to harm. Two, a robot must obey the orders given it by human beings except where such orders would conflict with the First Law. And three, a robot must protect its own existence as long as such protection does not conflict with the First or Second Laws.
    Isaac Asimov (1920–1992)

    Literature does not exist in a vacuum. Writers as such have a definite social function exactly proportional to their ability as writers. This is their main use.
    Ezra Pound (1885–1972)