Overloading Non-member Function
Friend functions play an extremely important role in operator overloading through giving the flexibility denied through the member functions of a class. They permit overloading of stream operators (<< or >>) for stream computation on user defined data types. The only difference among a friend function and member function is which; the friend function needs the arguments to be explicitly passed to the function and processes them explicitly, while the member function considers the first argument implicitly. A Friend functions could either be used along with unary of binary operators. Syntax of operator overloading along with friend functions is display below
Friend return type operator symbol(arg1 [arg2])
{
// body of operator friend function
}
Guidelines
It is essential to follow semantic rules and syntax of the language although extending the power of C++ by using operator overloading. Actually, operator overloading characteristics opens up vast vistas of opportunities for creative programmers. The following are a few guidelines which require to be kept in mind although overloading any operators to support user defined data types.