0

What is the spacial use of friend function in c++

actually I want to know why friend function

16th Dec 2016, 12:10 PM
Aakash
Aakash - avatar
1 Answer
+ 1
A friend function (or friend class) can be given access to the private members of a class by the class declaring it as a friend. For example: class A { private: friend void foo(); int a; } void foo() { //foo can manipulate A::a, even though it is private A x; x.a = 10; } As the joke goes: "only C++ gives friends access to their private member"!
16th Dec 2016, 1:58 PM
Ettienne Gilbert
Ettienne Gilbert - avatar