What is Operator Overloading in C++ ?

The ability to overload operators is one of the most powerful features of C++. The operators are overloaded so that they can perform special operations on the user defined classes. Say for example you create a class representing complex number. We can overload the + operator to add two complex numbers. When an operator is overloaded it original meaning is not lost in fact the type of objects that the operator can operate expands. Operators are overloaded by creating operator functions. It is created using the keyword operator. These functions can either be member of a class or then they have to be friend functions. Syntax: returntype class-name::operator#(arg-list) { } E.g. class Complex { private: float real; float imaginary; public: Complex operator+ (Complex); }; //overloaded + operator for class Complex Complex Complex::operator+ (Complex c) { Complex tmp; tmp.real = this.real + c.real; tmp.imaginary = this.imaginary + c.imaginary; return temp; } The only C++ operators that cannot be overloaded are dot (.), .*, ?:, sizeof, typeid and scope resolution operator (::).