I'm wondering how I can specify a template type as "parameter pack".
The commented line doesn't work because it can't deduce T (it has the same template parameters). On the next line I can fix that by supplying T but I'm stuck at how I should supply the parameter pack type (where the question marks are.).
template<typename T, typename... Args> T& Entity::addComponent(Args&&... args) const
{
//return entityManager->addComponent(std::forward<Args>(args)...);
return entityManager->addComponent<T, ?????>(std::forward<Args>(args)...);
}
I want to use Args as that type.
2 Answers 2
You don't need to specify the parameter pack template argument because it could be deduced from function arguments. So just specify the 1st template argument (and you have to do this because T can be deduced from nowhere). e.g.
return entityManager->addComponent<T>(std::forward<Args>(args)...);
// ^^^
If you want to specify the parameter pack template argument explicitly you could write it as
return addComponent<T, Args...>(std::forward<Args>(args)...);
// ^^^^^^^
2 Comments
It worked when I set Visual studio "Conformance Mode" setting to "No"