I have the following class:
class PhoneCall{
private:
string number;
public:
/*some code here */
};
Now, I have declared a function (not friend to PhoneCall) which does some specific operation and returns a PhoneCall object
PhoneCall callOperation()
Another which takes a PhoneCall object as parameter
void userCall(PhoneCall obj)
I was expecting it not to work unless it is explicity declared as a friend to that class.
Why and how do these functions work even when they are not friend to the PhoneCall class ?
A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class http://www.tutorialspoint.com/cplusplus/cpp_friend_functions.htm