Networking, Programming and Graphics Tutorials

Overloading binary operator using friend function - C++ [1/1]

Type:
Overloading binary operator using friend function - C++
Level: Intermediate Networking, Programming and Graphics Tutorials Networking, Programming and Graphics Tutorials 
Overloading binary operator using friend function - C++
Date: 2006-Dec-08
Overloading binary operator using friend function - C++
Visited: 1702 times
Overloading binary operator using friend function - C++
Rating: Overloading binary operator using friend function - C++
Overloading binary operator using friend function - C++
Author: Alex Plumpton

In the example using class adds, friend function can be used in the place of member function to overload the binary operator +. The difference is that the friend function requires two arguments while the member function requires only one. In the example using class adds, the member function declaration can be replaced by the friend function declaration as shown. The function definition has to be replaced as shown.

friend adds operator +(complex a1complex a2);
Parts operator +(adds a1adds a2)
{
return 
add((a1.m+a2.m),(al.n+p2.n));
}
Rate this tutorial:                    
Networking, Programming and Graphics Tutorials - Overloading binary operator using friend function - C++ [1/1] - Networking, Programming and Graphics Tutorials

Need a specific tutorial? Do not hesitate and submit a request!
Related Tags: "binary operator" c++ friend  overloading '= 'operator using friend function in c++  operator overloading using friend function  in c++ where and why friend function are used in operator overloading  overloading binary operator in c++  binary operator overloading '*' in C++  binary operator overloading '*' in C++  overloading binary * operator c++  overloading of binary operator  overloading << binary operator in c++