C Programming What is a friend function What is the differen

C++ Programming

What is a friend function? What is the difference between a friend function and a regular member function of a class?

Solution


A member function is the one which is defined inside a class and is a member of the class. It may either be a public private or protected function.

A friend function of a class is defined outside that class\' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.

A friend can be a function, function template, or member function, or a class or class template, in which case the entire class and all of its members are friends.

Friend function
   The friend keyword is used for declaration.
   While writing definition of function, the friend keyword is not required.
   Through a friend function, we can allow outside functions to access the class members.

C++ Programming What is a friend function? What is the difference between a friend function and a regular member function of a class?Solution A member function

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site