A friend member does not belong to an instance of the object. That is, it can not access by this
. Access will occur through an explicitly declared parameter.
The friendly member only delegates access to private and secured members to a role or class. That is, the code just states that a particular function or class can access its "inner" members as if it were part of the class, even though it is outside.
So if you declare that a
teste(MeuTipo objeto&)
function as
friend
within the
MeuTipo
class, when this function is set elsewhere, the
objeto
parameter can access all members of the
MeuTipo
class, even the
private
and
protected
.
Obviously if the function does not get a parameter with the specific type, it does not make much sense.
In a way we can say that the member friend
is static and will be set somewhere outside the class.
It recalls a purely virtual method, but the mechanism is completely different. The member definition will not be made by polymorphism or inheritance. On the contrary.
Remembering that there is a friendly class declaration too. This statement says that any friendly class can access members of this class. Obviously this can only occur with an explicit reference to this class.