If class B inherits class A privately. And class B has a friend function. Will the friend function be able to access the private member

If class B inherits class A privately. And class B has a friend function. Will the friend function be able to access the private member of class A?
A. Yes, because friend function can access all the members
B. Yes, because friend function is of class B
C. No, because friend function can only access private members of friend class
D. No, because friend function can access private member of class A also
 
Answer: c
Explanation: The friend function of class B will not be able to access private members of class A. Since B is inheriting class A privately, the members will become private in class B. But private members of class A won’t be inherited at all. Hence it won’t be accessible.
 

Tìm kiếm

Back
Top