What is the impact of using a friend function on encapsulation in C++? 

  • It enhances it. 
  • It doesn't affect it at all. 
  • It undermines it. 
  • It strengthens the class hierarchy.
Friend functions can access the private and protected members of a class. This can lead to a breach in encapsulation as they can potentially expose or modify class internals outside the usual member function framework. This undermines the very purpose of encapsulation.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *