A friendly member does not belong to an instance of the object, that is, can not access by this
, the access will be through a parameter explicitly declared.
The friendly member only delegates access to private and protected members to a function or class, so the code only states that a specific function or class can access its "internal" members as if it were part of the class, even if it were outside.
So if you declare that a function teste(MeuTipo objeto&)
as friend
within the class MeuTipo
, when this function is defined elsewhere, the parameter objeto
can access all class members MeuTipo
, even the private
and protected
.
Obviously if the function does not receive 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 else outside the class.
It sounds a little bit like a purely virtual method, but the mechanism is completely different. Member definition will not be made by polymorphism or inheritance, on the contrary.
Remember that there is the declaration of the friendly class as well. This statement says that the whole friendly class can access the members of this class. Obviously this can only occur by an explicit reference to this class.
Thank you very much! c:
– Miguel de Sousa