I was reading this. The answer given by @NPE talks about interesting historical facts & says that,
So, What is the reason behind removal of overload keyword? I don't have Design and Evolution of C++
by Stroustrup. What's wrong with overload keyword?
Stroustrup mentions in D&E 11.2.4 "The overload
Keyword" that the overload
keyword causes troubles when "merging" (or using) two libraries which both used the same function name (without namespaces*). For example, sqrt
in the C header math.h
versus the sqrt(complex)
from the C++ complex
header. If one of them declared the function as overloadable, but the other did not, you had to include the headers in such an order that overloading was enabled before it occurred:
// #include <complex>
overload sqrt;
complex sqrt(complex);
// #include <math.h>
double sqrt(double); // fine
// ---------------------------
// #include <math.h>
double sqrt(double);
// #include <complex>
overload sqrt; // ERROR: cannot allow overloading
// of an already declared function
complex sqrt(complex);
The possible workarounds are "unmanageable in all but the simplest cases".
(*) The overload
keyword was made obsolete with CFront 2.0, released in 1989. Namespaces were introduced into the standardization proposal in 1993.
The original intent of the keyword was to deal with two fears:
- Concern that undetected ambiguities could occur.
- Concern that a program could not properly be linked unless the programmer explicitly declared which functions were supposed to be overloaded.
The former fear proved largely groundless. The few problems found in actual use are dealt with by the order-independent overloading resolution rules. The latter fear proved to have no basis in a general problem with C separate compilation rules that had nothing to do with overloading.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With