0

Can someone help me appreciate the use of a friend function? Will be very thankful to them. â˜ș

10th Nov 2016, 11:13 AM
Orca
Orca - avatar
2 RĂ©ponses
0
Merits of friend function Friend function act as bridge between two classes by operating on their private datas. Must have access to source code for the class to make a function into friend. Able to access members without need of inheriting the class. Allows a more abvious syntax for calling a function rather than member function. For example num.square(); is less obvious than square(num); Can be declared either in the public or the private part of a class. Can be used to increase versatility of overloaded operator. Demerits of friend function Friend function have access to private members of a class from outside the class which violates the law of data hiding. Breach of data integrity Conceptually messy Lead to spaghetti-code situation if numerous friends muddy the boundary between classes. Maximum size of memory will be occupied by objects according to size of friend members. Cannot do any run time polymorphism in its members Hope it helps !
10th Nov 2016, 11:34 AM
hemant malbari
0
Thank you @hemant that was informative â˜ș
11th Nov 2016, 10:49 AM
Orca
Orca - avatar