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. 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:
CA(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 ?    9 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is inheritance in oop?

1036


Whats oop mean?

1054


what is the sylabus for priliminaries?

2181


Whats is abstraction in oops?

1083


Will I be able to get a picture in D drive to the c++ program? If so, help me out?

2199


What is inheritance and how many types of inheritance?

1105


What is difference between data abstraction and encapsulation?

1086


Why is polymorphism needed?

1076


c++ program to swap the objects of two different classes

2422


class type to basic type conversion

2419


What is coupling in oop?

1035


What does and I oop and sksksk mean?

1163


String = "C++ is an object oriented programming language.An imp feature of oops is classes and objects".Write a pgm to count the repeated words from this scenario?

2398


Which method cannot be overridden?

1100


How do you answer polymorphism?

1067