GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Tech FAQs  >  OOPS

 Print  |  
Question:  What is the purpose of friend function and is it overwhilmimg the private policy of oops concept?



January 01, 2006 05:03:17 #1
 Sameeksha Microsoft Expert  Member Since: October 2005    Total Comments: 231 

RE: What is the purpose of friend function and is it o...
 

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.

     

 

Back To Question