0

What the purpose of using "friend" keyword?

in c++ course , friend keyword used to access private member of another class. could you please give me an example as a clarification for this keyword. and what the benefit of using it.

29th Jun 2017, 12:15 PM
Johnny Shahin
Johnny Shahin - avatar
1 Réponse
0
for example you have class A has 2 private variables x and y. you define into the class a friend method for example friend void sum(A var). so when u define this function outside, the variable var will call x and y just by var.x and var.y even if they are private. that is the power of friend function.
30th Jun 2017, 12:47 PM
ussefshahid
ussefshahid - avatar