OOAD Functions Q/A #3


Question:Differentiate between friend function and member functions.

Answer:

Sr. No.Friend FunctionMember Function
1Friend function is a non-member function that has access to private and protected members of a class. It is not in the scope of the class in which it is declared.Member function is in scope of the class in which it is declared.
2A friend function cannot be called using object of the class.A member function is called using object of the class.
3friend keyword is used to declare a function as friend function.No such keyword is required.
4Class definition using friend function:
class trial
{	
private: {
Public:	{
friend void check ( );	
}	

void check ( );
Class definition using member function:
class trial
{	
private: {
Public:	{
void check ( );	
}	
trial:: void check ( );	
}	
5A friend function can be declared as friend in any number of classes.A member function is a part of any class in which it is declared.
6A friend function can be declared in private, public or protected scope of the class without any effect.A member function can be declared in private, public or protected scope of the class but have scope accordingly.
7While overloading binary operator, friend function takes two arguments.While overloading binary operator, member function takes one arguments.
Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements