Here is my issue. I have a container which takes in a pointer to the base class. When the container calls a certain method declared virtual, the derived classes can modify a pointer to the container, but only the base is a friend and since the container is compiled as a dll, it is not convenient to add friend Derived;开发者_JAVA技巧 to the container for each derived class. What can I do?
Thanks
Friendship is not inherited.
You have at least two options:
- Change the "container" to expose an interface that the derived classes can use
- Have the base class expose an interface to any classes derived from it
Without more details it's hard to tell, but it sounds like this architecture has rather poor encapsulation.
精彩评论