c++ - 创建不同模板化对象的模板化数组的模板化数组
问题描述
嘿,所以我目前正在研究一个非常简单的 ecs,我想将我Components
的所有 (其中有不同类型的)存储在数组中,其中也有不同的类型,并将所有这些数组存储在一个更大的数组中。像这样:
ComponentArray< ComponentArray< Component > > components;
现在我读到了这个,显然我必须ComponentArray
为以及创建一个基类,Component
并让它们MainArray
具有指向基类的指针。所以我认为声明应该是这样的:
ComponentArray< ComponentArrayBase< ComponentBase* >* > components;
并且在另一个实现文件的初始化中(因为它是一个静态类并且具有模板成员函数,所以我必须使实现成为一个.inl
文件并且不能在那里初始化数组):
ComponentArray< ComponentArrayBase< ComponentBase* >* > ComponentManager::components{/*creating some arrays here*/};
我的 Array 类如下所示:
template<typename ComponentType>
struct ComponentArrayBase{};
template<typename ComponentType>
struct ComponentArray : ComponentArrayBase<ComponentType>
{
ComponentType array[maxEntitys];
ComponentType& operator[](unsigned int index)
{
return array[index];
}
};
我的Components
样子是这样的:
struct ComponentBase{};
struct PositionComponent : ComponentBase
{
//some member variables
};
我想在哪里使用它,例如:
template<typename ComponentType>
ComponentType& ComponentManager::getComponent(Entity e, unsigned char index)
{
return *(*(components[index])[e]);
}
编译时出现以下错误:
error: no match for ‘operator*’ (operand type is ‘ComponentArrayBase<ComponentBase*>’)
return *(*(components[componentArray])[e]);
我不确定我所说的是否都有意义,所以非常感谢您的回答
车
解决方案
推荐阅读
- google-apps-script - 如何使用从远程 JSON 请求获得的值加载一个谷歌电子表格单元格?
- scala - “sbt clean compile”未解决的依赖关系
- java - 从 TCP/IP 连接读取双精度值 (JAVA)
- javascript - 禁用单击复选框;让父 div 处理
- matlab - 当我添加新输入时,如何使以前的输入在 Matlab 图中逐渐淡出
- webstorm - jsdoc:用模板扩展类型(用泛型扩展类型)
- cordova - 建立第一个科尔多瓦项目
- c# - 使用 C# SWI-Prolog DLL 获取非有限域边界
- python - Python:将元素插入到不同大小的数组中
- php - 导航栏如何使用 codeIgniter 在这个 php 代码中工作?