Hi, I'm learning the OOP of C++, and the book mention friendship function. From what I understand from the explanation and implementation in the book, friend function is used for operator overloading. So, my questions are:
1. Besides the purpose of overloading the operators, isn't the friend function and the member function the same? By this, I mean that instead of create a friend function, could I just create a member function to do the same job.
2. Is there other usage for the friend function?
Thanks for all the inputs.
Yes, well, friend is not a function; friend is a keyword that does what your book explains. It is true that most of the time, you will use the friend function to implement operator overloaded functions, but functions are not the sole use of friend. A class might be friends with another class.
A member function could do everything a friend function does, as long as there is public access. For example you implement the operator << and there is a public data() function. If what data() returns is what you want to display, then there is no problem: you could easily implement the operator, using data().
Gotcha. Thanks for the help, whiteflags.