InterviewSolution
| 1. |
How The Programmer Of A Class Should Decide Whether To Declare Member Function Or A Friend Function? |
|
Answer» A programmer should analyze the situations or requirements for deciding WHETHER to declare the member function or friend function for a class. When a function is declared as a friend, the function is able to access all the PRIVATE and protected member of the class. A member function can be used with encapsulation point of VIEW as friend functions violate the encapsulation and can also access all the private members ALTHOUGH they are not a PART of the class. From the security point of view, use of member function is safer than the friend function. A programmer should analyze the situations or requirements for deciding whether to declare the member function or friend function for a class. When a function is declared as a friend, the function is able to access all the private and protected member of the class. A member function can be used with encapsulation point of view as friend functions violate the encapsulation and can also access all the private members although they are not a part of the class. From the security point of view, use of member function is safer than the friend function. |
|