开发者

Is there a way for a derived implementation of a base function to access a class where base is a friend?

开发者 https://www.devze.com 2023-01-23 20:20 出处:网络
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,

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消