【发布时间】:2015-09-21 22:14:13
【问题描述】:
我一直致力于创建自己的实体组件系统,并且我准备通过执行以下操作来获取组件:
const auto& component = entity->GetComponent<ComponentType>();
上面的函数看起来像这样:
template <typename TyComponent>
TyComponent* Entity<T>::GetComponent() const
{
return &(GetComponent(TyComponent::Id());
}
如果找到,则返回基于关联 id 的组件,否则返回 nullptr。
- 我正在做的事情可行吗?
- 有没有办法确保只有从 Component 派生的类型可以
用作
GetComponent的参数?
【问题讨论】:
标签: c++ c++11 templates components entity-component-system