c++ friend

friend functions

friend function is a function that isn't a member of a class but has access to the class's private and protected members. Friend functions aren't considered class members; they're normal external functions that are given special access privileges. 

 

 

Class members as friends

friend class is a class all of whose member functions are friend functions of a class, that is, whose member functions have access to the other class's private and protected members. 

Suppose the friend declaration in class B had been:

friend class A;

In that case, all member functions in class A would have been granted friend access to class B. The following code is an example of a friend class:

posted @ 2025-06-14 17:53  ChuckLu  阅读(13)  评论(0)    收藏  举报