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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Multiple Inheritance in C++
- Does overloading work with Inheritance?
- Inheritance in C++
- Difference between Single and Multiple Inheritance in C++
- Difference between Inheritance and Polymorphism
- Runtime Polymorphism in various types of Inheritance in C++
- Mutual friendship of Classes in C++ with Examples
- Why do we need reference variables if we have pointers
- Similarities and Difference between Java and C++
- Macros and its types in C/C++
- How to find index of a given element in a Vector in C++
- Introduction to Complex Objects and Composition
- NULL undeclared error in C/C++ and how to resolve it
- std::remove_const in C++ with Examples