C++ ClassesLesson 37Free preview
C++ Friend Functions
This lesson is part of C++ · All levels
Summary
Friend is a non-member function that is specifically authorized to access private members of a class. Permission is given with the keyword friend in the class, and the function remains not a member of the class so it does not use a point when called. In addition to the function, a class can also be declared a friend so that the entire method can access the private class of another class.
Key points
- Friend is written outside the class but has access to private and protected members.
- Friend is not a member of the class, so he doesn't need any special calling objects.
- The Friend class gives one class full access to another.
- The use of friend should be limited because it can loosen the encapsulation.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.