Table of Contents
Previous Section Next Section

friend

The keyword friend grants a nonmember function access to the private members of a class. To specify a friend function, include that function's prototype in the public section of a class declaration and precede the entire prototype with the keyword friend. For example, in the following class, myfunc( ) is a friend, not a member, of myclass:

class myclass {
  // ...
public:
  friend void myfunc(int a, float b);
  // ...
};

Keep in mind that a friend function does not have a this pointer because it is not a member of the class.


Table of Contents
Previous Section Next Section