I have class A. And I have class B. And I have many-many classes derived from class B.
I want to achieve this: derivatives of B should have access to the protected variables of A. Whithout each of them containing an instance of A, which would need a lot of memory.
So I guess public inheritance is not a good idea this time. How do I solve this?
Thanks!
You could do it with
friendand accessor functions. This does trustBto stay offA‘s privates – don’t see a good way to let onlyBand subclasses access only protected members ofAunless there’s an inheritance relationship betweenAandB.