Guideline that should be followed while using friend function

Guideline that should be followed while using friend function.

- When the application is needed to access a private member of another class, the only way is to utilize the friend functions.
- The following are the guidelines to handle friend functions :
1. Declare the function with the keyword ‘friend’ that is followed by return type and followed by the function name.
2. Specify the class whose private members are to be accessed in the friend function within parenthesis of the friend function.
3. Write the code of the friend function in the class.
- The following code snippet illustrates the use of friend function :
friend void display(car); //Friend of the class 'car'
void display(car myCar)
   cout<<"\nThe color of my car is : "<<myCar.color;
   cout<<"\nThe speed of my car is : "<<myCar.speed;
What is Polymorphism? - C++
What is Polymorphism? - Polymorphism means the ability to take more than one form. An operation may exhibit different behavior in different instances....
What is Inheritance? - C++
What is Inheritance? - Inheritance: One of the most important features of OO design is code-reusability......
Define object, classes and instances.
Define object, classes and instances - Object is the basic run time entity in an Object Oriented (OO) System...
Post your comment