Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is friend function?

Answer Posted / niranjan ambati

If you want to explicitly grant access to a function that
isn’t a member of the current class then friend functions
can be useful. It allows external functions to access the
private members of a class. You can declare a global
function as a friend, and you can also declare a member
function of another class, or even an entire class, as a
friend.
The compiler ignores the access level (public, private,
protected) where friend functions are declared. Friend
functions are inherently public.
Friend function should be used as minimum as possible, but
it can be used safely in the following way.. by calling the
same class object where friend function exists.. if you
want to interact with other class then call that class
objects in friends function which interacts the private
members of the class.
class NA
{
int i;
public:
NA(int i):i(t){}
friend void fun(NA *);
};
void fun(NA *obj)
{
cout <<obj->i<<endl;
}
void main()
{
NA obj(22);
fun(&obj);
};

Is This Answer Correct ?    5 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is overriding vs overloading?

1049


write knight tour problem which is present in datastructure

2637


What is inheritance in oop?

1018


What is the important feature of inheritance?

1112


What is abstraction in oop?

1117


What is protected in oop?

1051


What does oop mean in snapchat?

1220


How do you use inheritance in unity?

1062


what is graphics

2442


What are the data types in oop?

1087


What does no cap mean?

1041


Advantage and disadvantage of routing in telecom sector

1294


write a program using c++ to implement single contiguous memory mangement techniques.display the content of the main memory after yhe allocation of jobs and percentage of the wastage of the main memory

3209


What is polymorphism and its types?

1051


What is persistence in oop?

1132