What is the purpose of friend function and is it overwhilmimg the private policy of oops concept?

Showing Answers 1 - 1 of 1 Answers

samiksc

  • Jan 19th, 2006
 

A friend function can access all private protected and public data of a class.

A class has to declare a function or another class as a friend. Also the friendship is one way. Class A is friend of class B does not mean that class B is friend of class A. So the control is in the hands of a class.

That way it is not against the data hiding principle of OOPs. It may be used to make exceptions to the normal rules of private and protected data. It should be used wisely and it should not be a practice to use friends heavily.

Some OOPs languages like C# do not support a concept of friends.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions