A Friend function is a function defined outside the class, but it has access to all private and protected members of the class. To declare a friend function, it’s prototype must be declared inside the class, preceding it with keyword “friend”. Check Friend Function for more information.
A Member function is a function defined in the class as a member of the function. It is usually declared inside the class definition.
Friend Function | Member Function |
These functions can be declared in multiple Classes. | Member functions can be declared only in there class. |
Friend function can typically access private, protected data members of multiple classes. | Member function can access private, protected member of their own class. |
Friend function does need to be called with any class object. | Member function can only be called using class objects. |
Friend function doesn’t have this pointer | Member function has this pointer. |
Friend keyword needs to be preceded before function declaration to define it as friend function. | No such keyword needed. |
Friend function can be declared in private/protected/public section of a class without affecting it’s behavior. | Member functions behavior changes based on the section where it is defined. |
Derived Classes doesn’t inherit friend functions. | Derived classes do inherit member functions. |
Friend function can’t be defined as static functions. | Member functions can be defined ass static functions. |