class Component_Base{};
class Rect_Component : Component_Base
{
public:
struct Info
{
uInt width;
uInt height;
};
};
template<typename... Args>
class ECSData
{
private:
tuple<optional_ECSVector_wrapped_t<Args>...> data;
public:
template<typename... Info>
void createEntity(Info&&... info) {
}
};
int main()
{
ECSData<Rect_Component, Text_Component, Rendering_System> ecsData;
ecsData.createEntity(Rect_Component::Info{ .width{200}, .height{500} });
return 0;
}
在上面的代码中,我将 Rect_Component::Info
传递给 createEntity()
。
鉴于上面的代码,可以在 createEntity()
内部让模板参数推导推断出 T::Info
中的 T
是什么,并使用说T?
毕竟我在调用中编写了 Rect_Component
,所以我怀疑一定有办法
最佳答案
考虑:
struct Not_Rect_Component {
using Info = Rect_Component::Info;
};
这无法与您的原始 Rect_Component
提供的 Info
区分开来,因此您无法推断其中之一。您必须在 Info
中提供一个 typedef,它指的是正确的父类型。
关于c++ - 使用模板参数推导推导类的 "outer class",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59429222/