In this blog post we will learn about friend function and operator overloading. The operator overloading function must be either non static member function or friend function. In case of member function , the member function will have no arguments for unary operators and only one argument for binary operators. In case of friend function ,the friend function will have one argument for unary operators and two arguments for binary operators.

Example of Binary operator overloading: +

Using friend function: Friend function and operator overloading


Example of Unary operator overloading:

The increment (++) is unary operator in C++. Here we will learn how to overload this operator for user defined data types. first example will be with member function and second will be implemented with friend function.


Using friend function:
( In this implementation the operator function will take one argument).


Related Contents to follow