-1
我有一个EntityComponent-System,并且有一个组件应该调用各种其他组件。对于这个例子,我选择了一个布尔函数结果的简单组合。C++ Template Variadic - 为每个模板参数调用一次成员函数
ResultCombinerComponent具有可变参数模板参数,并且对于这些参数中的每一个参数,都应按照给定模板参数的顺序调用函数。顺序非常重要。
之后将函数调用的结果合并。
在下面的代码我刚刚更换的部件,我不知道如何实现与伪C++
template<typename... Args>
class ResultCombinerComponent
{
template<typename T>
bool calcSingleResult()
{
return getComponent<T>()->calcResult();
}
bool calcResult()
{
bool result = true;
for (int i = 0; i < sizeof...(Args); i++) // doesn't work
{
if (!calcSingleResult<Args(i)>() // doesn't work
{
result = false;
break;
}
}
return result;
}
}
class A
{
bool calcResult();
}
class B
{
bool calcResult();
}
class C
{
bool calcResult();
}
[这](http://stackoverflow.com/questions/12030538/calling-a-function-for-each-variadic-template-argument -和-一个数组)可以给你一些信息。 – LogicStuff
我已阅读过这个帖子和其他许多类似帖子,并试图将其应用于我的特定问题,但无法将其应用于我的特定问题。 – keyboard
你没有在任何地方使用'...'(参数包扩展)。还有一件事 - 你想用所提供的类型来计算一些东西? ...因为代码中没有实际的实例/对象。 – LogicStuff