Content deleted Content added
No edit summary |
ClueBot NG (talk | contribs) m Reverting possible vandalism by 210.212.161.97 to version by Kendev55. Report False Positive? Thanks, ClueBot NG. (2527287) (Bot) |
||
Line 4:
Normally, a [[function (computer science)|function]] that is defined outside of a class cannot access such information. Declaring a function a '''friend''' of a class allows this, in languages where the concept is supported.
A friend function is declared by the class that is granting access, explicitly stating what function from a class is allowed access. A similar concept is that of [[friend class]].
Friends should be used with caution. Too many functions or external classes declared as friends of a class with protected or private data may lessen the value of [[separation of concerns|encapsulation]] of separate classes in object-oriented programming and may indicate a problem in the overall architecture design. Generally though, friend functions are a good thing for encapsulation, as you can keep data of a class private from all except those who you explicitly state need it, but this does mean your classes will become tightly coupled.
|