c++ - C++中的前向声明和循环依赖
问题描述
我正在尝试在 C++ 中实现一个简单的关系。它是这样的:
- 传送将物体位置从一条车道更改到另一条车道
- 车道包含一些其他对象以及多个传送点。这提出了一个我无法解决的循环依赖问题。我已经在使用前向声明,但我不知道下一步该做什么。
车道.h
#include "Teleport.h"
class Lane
{
public:
std::map<long long, object> object_container;
std::map<long long, Teleport> teleports_container;
void add_Object(///) { object_container.emplace(//object//); }
void add_Teleport(const Teleport &t) { teleport_container.emplace(t._uid, t); }
Object &get_Object(long long uid) { return object_container.at(uid); }
Teleport &get_Teleport(long long uid) { return teleports_container.at(uid); }
}
传送.cpp
#include "Lane.h"
#include "Teleport.h"
void Teleport::teleport_Object(long long tp_uid)
{
_destination.add_Object(_origin.get_Object(tp_uid));
}
}
传送.h
class Lane;
class Teleport
{
public:
const Lane &_origin;
const Lane &_destination;
Teleport(const Lane &origin, const Lane &destination)
: _origin{origin}, _destination{destination}{}
void teleport_Object(long long tp_uid);
};
Teleport.cpp 的编译错误“错误:不完整类型'const class Lane'的无效使用”不胜感激。
解决方案
推荐阅读
- c++ - 直接启动应用程序时控制台中的 C++ 彩色文本不显示
- ios - 如何将自定义视图添加到上下文菜单 iOS
- twilio - 使用 twilio notify api,是否可以为每条消息插入唯一的跟踪链接?
- postgresql - Potgres createuser:创建新角色失败:错误:角色“postgres”已经存在
- button - 检测到点击 UIImagePickerController 的取消按钮?
- filesystems - 如何通过 Azure 数据块连接我的窗口网络共享路径
- javascript - 动态 Javascript 范围滑块
- c# - 在另一个窗口中访问公共 ObservableCollection
- javascript - Expo SDK40 升级 TypeError: undefined is not a function (near '..._core.Platform.select...')
- web-services - 调用 Web 服务时 ColdFusion 对象覆盖其他对象