Javatpoint Logo
Javatpoint Logo

Advantages and Disadvantages of Friend Function in C++

We have created the friend function to access the different modifiers in C++ Object Oriented Programming System such as Protected, Private and Public. The friend function or the friend class will usually be defined outside the course but still has access to the class's private, protected and public members defined in the class code.

Advantages Disadvantages
The declaration can be anywhere in the code It is not passed to the derived class
There is no need to create an object to call it. They don't have a storage-specified class.
Non-public members of the class can also be accessed using the friend function. The friend function comes in handy when multiple classes are tied together.
It can add extra functionality. Allows private and protected members to be shown as the information of the class.
Enables programming experience to be more efficient than ever before. It can have both public and private protected members in the same class in which it has been defined.

C++ code

Output:

/tmp /mB gjSey FC Z.o
3135

C++ code

Output:

/tmp /mB gjSey FC Z.o
After performing the operations, the value for X we have got is 3979

C++ code

Output:

/tmp /mB gjSey FC Z.o
Dear User, please enter the value for the variable first no: 35
Dear User, please enter the value for the variable second no: 365
Hey! User, the maximum number among the inputs entered by you is: 365

Next TopicC++ Pre-processors





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA