Function Overloading
Function Overloading
7. When are friend functions used? Write syntax for declaration of friend function.
A. Friend functions are used in the following situation: When two classes must share a
common function, C++ allows the common function to be shared between the two classes
by making the common function as a friend to both the classes. This allows the function to
have access to the private data of both of these classes.
The friend function is declared within a class with the prefix friend.
Syntax:
class class_name
{
public:
friend void function1(void);
}
As the body of the inline function is substituted in place of a function call, the size of
the executable file increases and more memory is needed.