Ok, I'll take a crack at this too.
As pointed out by everyone, the syntactic difference between a declaration of a member function and a friend function is, reasonably enough, the friend
keyword.
Here is one way to think about this. A member function has an implicit parameter: the pointer to the object itself. E. g. inside set_values
you can use the members width
and height
, and they would be the members of the object whose set_values
was called.
On the other hand, you cannot use identifiers width
or height
by themselves inside duplicate()
, because it is not a member function, and therefore it does not have the implicit parameter, i. e. it is not associated with any particular object. What friendship means, is that duplicate()
has access to the private members of any CRectangle
object which is passed to it, or which is a local variable within its scope.
Another point: the friend declaration is not even really a declaration of the function. It is simply a note to the compiler that if this particular function is ever defined, it is to be given access to the private members of this class.