C++ has the ability to provide the operators with a special meaning for a data type, this ability is known as operator overloading. Operator overloading is a compile-time polymorphism. For example, we can overload an operator '+' in a class like String so that we can concatenate two strings by just using +.
Dec 6, 2021An overloaded operator is just a function with a funny name. It should be placed exactly like any other function. – n. m. could be an AI.Compiler can't find overloaded operator<< while compiling. C++Why can't the compiler find this operator<< overload? - Stack Overflowhow compiler identifies the type when overloading new operator in How does the operator overload resolution work within namespaces?More results from stackoverflow.com
Operator overloading is a compile-time polymorphism. For example, we can overload an operator '+' in a class like String so that we can concatenate two strings by just using +. Other example classes where arithmetic operators may be overloaded are Complex Numbers, Fractional Numbers, Big integers, etc.
The operator keyword declares a function specifying what operator-symbol means when applied to instances of a class. This gives the operator more than one meaning, or "overloads" it. The compiler distinguishes between the different meanings of an operator by examining the types of its operands.
To overload an operator, a function must be written with the name operator followed by the symbol for the operator being overloaded. To use an operator on class objects, that operator MUST be overloaded - with two exceptions.