Question 1302 – Nielit STA [02-12-2018]
December 10, 2023Question 1306 – Nielit STA [02-12-2018]
December 10, 2023OOPS
Question 105
|
A friend function in C++ can’t be used with:
Member function
|
|
Object
|
|
Class
|
|
Class template
|
Question 105 Explanation:
→A C++ friend functions are special functions which can access the private members of a class.
→A friend function is declared by the class that is granting access, so friend functions are part of the class interface, like methods.
→Friend functions allow alternative syntax to use objects, for instance f(x) instead of x.f(), or g(x,y) instead of x.g(y). Friend functions have the same implications on encapsulation as methods.
→Friend of the class can be member of some other class.
→Friend of one class can be friend of another class or all the classes in one program, such a friend is known as GLOBAL FRIEND.
→Friend can access the private or protected members of the class in which they are declared to be friend, but they can use the members for a specific object.
→Friends are non-members hence do not get “this” pointer.
→Friends, can be friend of more than one class, hence they can be used for message passing between the classes.
→Friend can be declared anywhere (in public, protected or private section) in the class.
→A friend function is declared by the class that is granting access, so friend functions are part of the class interface, like methods.
→Friend functions allow alternative syntax to use objects, for instance f(x) instead of x.f(), or g(x,y) instead of x.g(y). Friend functions have the same implications on encapsulation as methods.
→Friend of the class can be member of some other class.
→Friend of one class can be friend of another class or all the classes in one program, such a friend is known as GLOBAL FRIEND.
→Friend can access the private or protected members of the class in which they are declared to be friend, but they can use the members for a specific object.
→Friends are non-members hence do not get “this” pointer.
→Friends, can be friend of more than one class, hence they can be used for message passing between the classes.
→Friend can be declared anywhere (in public, protected or private section) in the class.
Correct Answer: B
Question 105 Explanation:
→A C++ friend functions are special functions which can access the private members of a class.
→A friend function is declared by the class that is granting access, so friend functions are part of the class interface, like methods.
→Friend functions allow alternative syntax to use objects, for instance f(x) instead of x.f(), or g(x,y) instead of x.g(y). Friend functions have the same implications on encapsulation as methods.
→Friend of the class can be member of some other class.
→Friend of one class can be friend of another class or all the classes in one program, such a friend is known as GLOBAL FRIEND.
→Friend can access the private or protected members of the class in which they are declared to be friend, but they can use the members for a specific object.
→Friends are non-members hence do not get “this” pointer.
→Friends, can be friend of more than one class, hence they can be used for message passing between the classes.
→Friend can be declared anywhere (in public, protected or private section) in the class.
→A friend function is declared by the class that is granting access, so friend functions are part of the class interface, like methods.
→Friend functions allow alternative syntax to use objects, for instance f(x) instead of x.f(), or g(x,y) instead of x.g(y). Friend functions have the same implications on encapsulation as methods.
→Friend of the class can be member of some other class.
→Friend of one class can be friend of another class or all the classes in one program, such a friend is known as GLOBAL FRIEND.
→Friend can access the private or protected members of the class in which they are declared to be friend, but they can use the members for a specific object.
→Friends are non-members hence do not get “this” pointer.
→Friends, can be friend of more than one class, hence they can be used for message passing between the classes.
→Friend can be declared anywhere (in public, protected or private section) in the class.
Subscribe
Login
0 Comments