If I create base class A and A is a friend of class B, can a class derived from A access B to its liking, or else what is it allowed?
Thanks
It is not possible.
What is a Derived Class? A derived class is a class that is constructed from a base class or an existing class. It has a tendency to acquire all the methods and properties of a base class. It is also known as a subclass or child class.
Difference between Inheritance and Friendship in C++: 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).
Both concepts are completely different.
struct A{};
struct Ader : A{};
struct B{
friend struct A;
};
No. Friendship is not inherited in C++. It is also not transitive.
Ader
can not access B
as a friend unless explicitly given friendship by B, just because it's base A
is a friend of B
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With