I’m trying to properly encapsulate a class A, which should only be operated on by class B.
However, I want to inherit from class B.
Having A friend B doesn’t work — friendship isn’t inherited.
What’s the generally accepted way of accomplish what I want, or am I making a mistake?
To give you a bit more color, class A represents a complex system’s state. It should only be modified by B, which are actions that can be applied to change class A’s state.
I assume you want to allow descendants of B to access A directly? If A and B are tightly coupled, you can make A a protected class definition within B itself, instead of being an independent definition. E.G.
Another idea is to create protected methods on B that delegate their actions to A. E.G.