1

I'm learning C++ and I'm confused about true meaning of overloaded operators and functions.

In local literature I've used, there is a translation of overloaded functions with "load" as a noun, not as a verb - so it has the meaning of "an excessive load or burden" although in this case, as I understood it, nothing is "overloaded" in that sense (e.g. similar to circut overload).

If we consider "load" as an verb, then it means function is "loaded once more time", over the existing definition.

Am I on the right path, and what would be the proper interpretation of "overloading" in the case of programming?

phidrho
  • 170
  • 6
  • Overloading functions is the set of functions with the same name (but different signature). Then [overload resolution](https://en.cppreference.com/w/cpp/language/overload_resolution) is there to pick the correct one, depending of given arguments. – Jarod42 Jul 16 '21 at 13:01
  • Does this answer your question? [What are the basic rules and idioms for operator overloading?](https://stackoverflow.com/questions/4421706/what-are-the-basic-rules-and-idioms-for-operator-overloading) – gstukelj Jul 16 '21 at 13:01

2 Answers2

7

The term overloading in programming stems from semantic overloading - i.e. assigning multiple meanings to a certain word or phrase.

In case of C++, the same function or operator can be overloaded - meaning there can be multiple versions of it for different argument types. Which of the overloads is invoked is then determined from the context of the call by the process called overload resolution.

rustyx
  • 80,671
  • 25
  • 200
  • 267
  • Amazing, thank you! I have never heard that term in english before (semantic overloading), now it totally makes sense.:) – phidrho Jul 18 '21 at 06:41
2

In C++ "overload" refers to candidate functions during overload resolution.

In simpler terms, this is when there are multiple function or operator declarations with the same identifier, but with either different arguments or different qualifiers. Each of these function is an overload, and the process by which the compiler chooses which function should be called is overload resolution.

For example, the following declares two overloads for the function foo which differ by their argument type :

void foo(int);
void foo(double);
François Andrieux
  • 28,148
  • 6
  • 56
  • 87