a use a member while you can and a friend when


A: Use a member while you can and a friend when you need to.

Sometimes friends are better syntactically (e.g., in class Fred, friend functions let the Fred parameter to be second, whereas members require it to be first). Another good employ of friend functions are the binary infix arithmetic operators. For example :-  a Complex + a Complex must be defined as a friend instead of a member if you wish to allow a Float + a Complex as well (member functions don't let promotion of the left hand argument, as that would modify the class of the object it is the recipient of the member function invocation).

In other cases, select a member function on a friend function.

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: a use a member while you can and a friend when
Reference No:- TGS0217899

Expected delivery within 24 Hours