Friend function

In object-oriented programming, a friend function, that is a "friend" of a given class, is a function that is given the same access as methods to private and protected data.[1]

A friend function is declared by the class that is granting access, so friend functions are part of the class interface, like methods. Friend functions allow alternative syntax to use objects, for instance f(x) instead of x.f(), or g(x,y) instead of x.g(y). Friend functions have the same implications on encapsulation as methods.

A similar concept is that of friend class.

  1. ^ Holzner, Steven (2001). C++ : Black Book. Scottsdale, Ariz.: Coriolis Group. p. 397. ISBN 1-57610-777-9. 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 protected, and private data members.)

© MMXXIII Rich X Search. We shall prevail. All rights reserved. Rich X Search