October 15th, 2003, 09:44 AM
for what reason should I use friend function?
isn't friend function break the encapsulation concept of class?
Last edited by zacharya; October 15th, 2003 at 09:48 AM.
October 15th, 2003, 11:25 AM
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
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!