In C++, friendship is not inherited. If a base class has a friend function, then the function doesn’t become a friend of the derived class(es).
For example, following program prints error because show() which is a friend of base class A tries to access private data of derived class B.
Thanks to Venki for the above code and explanation.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Mutual friendship of Classes in C++ with Examples
- Difference between Single and Multiple Inheritance in C++
- Difference between Inheritance and Polymorphism
- Multiple Inheritance in C++
- Does overloading work with Inheritance?
- Inheritance in C++
- Runtime Polymorphism in various types of Inheritance in C++
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- INT_MAX and INT_MIN in C/C++ and Applications
- fesetround() and fegetround() in C++ and their application
- Queries to insert, delete one occurrence of a number and print the least and most frequent element
- Get first and last elements from Array and Vector in CPP
- Similarities and Differences between Ruby and C++
- Generate an array of given size with equal count and sum of odd and even numbers
- Similarities and Difference between Java and C++
- Change/add only one character and print '*' exactly 20 times
- Comma in C and C++
- How does "void *" differ in C and C++?
- What are the operators that can be and cannot be overloaded in C++?
- Data type of character constants in C and C++