Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Does "Overloaded"/"Overload"/"Overloading" Mean?

What does "Overloaded"/"Overload" mean in regards to programming?

like image 647
Steve Avatar asked Nov 14 '08 12:11

Steve


People also ask

What do u mean by overloading?

To overload is to load an excessive amount in or on something, such as an overload of electricity which shorts out the circuits. Overloading causes a "Too much!" situation. To overload is to push something or someone too far. A supervisor can overload an employee by assigning too much work.

What does overloaded mean in C++?

C++ lets you specify more than one function of the same name in the same scope. These functions are called overloaded functions, or overloads. Overloaded functions enable you to supply different semantics for a function, depending on the types and number of its arguments.

What does +1 overload mean?

1. It means that the Insert method has one more version (overload) that use a different set of parameters.

What does overload mean in electrical?

An electric overload occurs when too much current passes through electric wires. The wires heat and can melt, with the risk of starting a fire. The solution? Avoid plugging several power-hungry items of equipment into the same line.


2 Answers

It means that you are providing a function (method or operator) with the same name, but with a different signature. For example:

void doSomething();
int doSomething(string x);
int doSomething(int a, int b, int c);
like image 164
Filip Frącz Avatar answered Sep 27 '22 21:09

Filip Frącz


Basic Concept

Overloading, or "method overloading" is the name of the concept of having more than one methods with the same name but with different parameters.

For e.g. System.DateTime class in c# have more than one ToString method. The standard ToString uses the default culture of the system to convert the datetime to string:

new DateTime(2008, 11, 14).ToString(); // returns "14/11/2008" in America

while another overload of the same method allows the user to customize the format:

new DateTime(2008, 11, 14).ToString("dd MMM yyyy"); // returns "11 Nov 2008"

Sometimes parameter name may be the same but the parameter types may differ:

Convert.ToInt32(123m);

converts a decimal to int while

Convert.ToInt32("123");

converts a string to int.

Overload Resolution

For finding the best overload to call, compiler performs an operation named "overload resolution". For the first example, compiler can find the best method simply by matching the argument count. For the second example, compiler automatically calls the decimal version of replace method if you pass a decimal parameter and calls string version if you pass a string parameter. From the list of possible outputs, if compiler cannot find a suitable one to call, you will get a compiler error like "The best overload does not match the parameters...".

You can find lots of information on how different compilers perform overload resolution.

like image 25
Serhat Ozgel Avatar answered Sep 27 '22 21:09

Serhat Ozgel