Can a friend function of a class access the private members of that class? 

  • Only if the function is defined inside the class 
  • No, it can't 
  • Yes, it can 
  • Only if the class has no protected members
Friend functions are specially designated functions that are allowed to access the private and protected members of a class. This is their primary purpose. Although they can breach the encapsulation principle, they're useful in scenarios where certain external functions require closer integration with a class's internals.
Add your answer
Loading...

Leave a comment

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