Chapter 14: Problem 5
Why is it not always a good idea to make an entire class a friend of another class?
Short Answer
Expert verified
Question: Explain the concept of friendship in C++ and discuss the potential drawbacks and risks of making an entire class a friend.
Answer: In C++ object-oriented programming, friendship allows one class or function to access private and protected members of another class. This can be useful in some cases but should be applied cautiously. Making an entire class a friend has potential drawbacks and risks, such as violating encapsulation, increasing the potential for bugs and errors, and reducing code reusability. To maintain good programming practices, friendships should be established following the principle of least privilege, granting access only to necessary functions or classes.