Content deleted Content added
Reverted 1 good faith edit by 49.205.77.95 using STiki |
Typo fixing and general fixes using AWB |
||
Line 1:
In [[object-oriented programming]], a '''friend function''' that is a "friend" of a given [[class (computer science)|class]] is allowed access to <code>private</code> and <code>protected</code> [[data]] in that class that it would not normally be able to as if the data was <code>public</code>.
<ref>{{cite book|last=Holzner|first=Steven|title=C++ : Black Book|year=2001|publisher=Coriolis Group|___location=Scottsdale, Ariz.|isbn=1-57610-777-9|page=397|quote=When you declare a function a friend of a class, that function has access to the internal data members of that object (that is, its
</ref>
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.
==Use cases==
|