Friends

Let's discuss friends in this lesson.

Friends

Friends of a class template have access to all members of the class template.

A class or a class template can have a friendship to class or class templates, function or function templates, and types.

Rules:

  1. The declaration of friends can be made at an arbitrary place in the class declaration.
  2. The access rights in the class have no influence.
  3. Friendship will not be inherited.
  4. Friendship is not transitive.

A friend has unrestricted access to the members of the class.

General Friends

A class or a class template can grant friendship to each instance of a class template or a function template.

Create a free account to view this lesson.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy