An operator could be overloaded with the help of a special function called operator function, the general form of an operator function is:
return type <class name> : : operator op (parameters)
{
….............
}
{
….............
}
Operator function must be either member function or friend function.
A friend function will have one argument for unary operators and two for binary while a member function will have no argument for unary operators and only one for binary operators.
The process of overloading involve following steps:
(1) creates the class that defines the data types that is to be used in overloading operations.
(2) Declare the operator function Operator op in the public part of the class. It may be either member function or friend function.
(3) Define the operator function to implement the required operation.
A friend function will have one argument for unary operators and two for binary while a member function will have no argument for unary operators and only one for binary operators.
The process of overloading involve following steps:
(1) creates the class that defines the data types that is to be used in overloading operations.
(2) Declare the operator function Operator op in the public part of the class. It may be either member function or friend function.
(3) Define the operator function to implement the required operation.
Tags:
Cpp