使用模板参数推导类的"outer class"
Deducing the "outer class" of a class with Template Argument Deduction
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 类和头文件
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 使用模板进行堆栈实现; "name followed by :: must be a class or namespace"
- "Undefined class"作为is_base_of的论据
- 如何将class.cpp和class.hpp编译为一个.o文件
- '{'标记之前的预期类名,然后在预声明时无效使用不完整的类型'class class_name'
- 如何使用"derived input class"创建派生类?
- 错误:"Left of getValue must have class/struct/union"
- ' class a : b ' 和 ' class a : public b ' 之间的继承类不同
- Pybind11 Class Definition
- 在C++中使用没有合作伙伴Class/Cpp文件的头文件是否实用
- C2011 'CMemDC':Visual Studio 2019中的'class'类型重新定义
- TypeError: [c++ addon class] 不是构造函数
- C++ class template
- 当初始值设定项是基类名时'initializer does not name a non-static data member or base class'错误
- Clearing Class Foo with new(pFoo) Foo()
- C++ class vs a library
- 继承类时"invalid use of incomplete type ‘class tree_node_t’"
- 使用模板参数推导类的"outer class"