C++:概念循环包含问题

发布于 2024-10-01 01:27:37 字数 268 浏览 1 评论 0原文

我正在为游戏引擎制作一个基于组件的实体系统。

我有一个实体类,它必须包含组件基类标头才能定义组件数组 private Component* Components[ 123 ]

但是,在组件基类中我必须定义一个 < code>private Entity* OwnerEntity,因为组件知道它属于谁是至关重要的!

这导致 Entity.h 需要 Component.h,反之亦然 ->循环引用

如何解决这个问题?

I'm making a component based entity system for a game engine.

I have an entity class, which has to include the component base class header in order to define the array of components private Component* components[ 123 ]

However, in the component base class I have to define a private Entity* ownerEntity, beacuse it is crucial that a component knows who it belongs to!

This results in Entity.h needing Component.h and vice-versa -> Circular reference

How can I solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慕烟庭风 2024-10-08 01:27:37

只要您只需要您的类包含对其他类的指针引用,您就可以跳过真正的包含文件并使用空的前向声明,例如class组件;

您将需要在源文件中完整包含您取消引用指针或使用引用来调用 Component 上的方法。

As long as you only need your class to contain pointers or references to the other classes, you can skip the real include file and use an empty forward declaration like class Component;.

You will need the full include in the source file where you dereference the pointers or use the reference to call methods on Component.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文