36. Overloading

By | September 24, 2021

If we create two or more members having the same name but different in number or type of parameter, it is known as C++ overloading. 

In C++, we can overload:

  • methods,
  • constructors, and
  • indexed properties

It is because these members have parameters only.

Types of overloading in C++ are:

  • Function overloading
  • Operator overloading
C++ Overloading

C++ allows you to specify more than one definition for a function name or an operator in the same scope, which is called function overloading and operator overloading respectively.

An overloaded declaration is a declaration that is declared with the same name as a previously declared declaration in the same scope, except that both declarations have different arguments and obviously different definition (implementation).

When you call an overloaded function or operator, the compiler determines the most appropriate definition to use, by comparing the argument types you have used to call the function or operator with the parameter types specified in the definitions. The process of selecting the most appropriate overloaded function or operator is called overload resolution.

Leave a Reply

Your email address will not be published. Required fields are marked *