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.
Loading...
Related Quiz
- A function that does not return a value has a return type of _______.
- Which of the following smart pointers does not take ownership of the pointed object?
- You are developing a simulation that runs in discrete time steps...
- The goto statement can only jump to labels within the same _______.
- What will be the output of a loop if the continue statement is placed before the print statement inside the loop?