Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++

Question: 1 / 565

How can a function outside a class access private members of the class?

By being declared a friend within the class

Functions outside of a class cannot directly access private members of that class. However, by being declared a friend within the class, the function is granted permission to access private members. Inheritance (B) can provide access to protected members, but not private ones. Using public member functions (C) also does not give access to private members. Option D is also incorrect because with the appropriate declaration, functions can access private members of a class.

Get further explanation with Examzify DeepDiveBeta

By inheriting the class

Using public member functions

It cannot access private members

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy