for what reason should I use friend function?
isn't friend function break the encapsulation concept of class?
Printable View
for what reason should I use friend function?
isn't friend function break the encapsulation concept of class?
Answer to part 1: you should try to avoid using friends unless it is absolutely necessary. When is it necessary? Rarely. Probably the most common (and "safest") is if you make a contained class a friend of the containing class. At least, this is the situation in which I've mostly found myself using friends.
Answer to part 2: Yes. It also increases coupling, so is doubly a bad thing