+ 1

Friend function as private or public

Hi Refer code below : It works fine. But just have a query on friend function. It can be private or public or anywhere ? Does it make any difference based on access specifier It is defined inside ? https://sololearn.com/compiler-playground/ca5VNO2jSp44/?ref=app

14th Dec 2023, 12:56 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Answers
+ 3
"The friend declaration appears in a class body and grants a function or another class access to private and protected members of the class where the friend declaration appears." "Access specifiers have no effect on the meaning of friend declarations (they can appear in private: or in public: sections, with no difference)." https://en.cppreference.com/w/cpp/language/friend
14th Dec 2023, 1:24 PM
Bob_Li
Bob_Li - avatar
+ 3
Thanks Bob_Li
14th Dec 2023, 1:38 PM
Ketan Lalcheta
Ketan Lalcheta - avatar