1

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.

asked Feb 17, 2020 at 10:37
0

2 Answers 2

1

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)...);
// ^^^^^^^
answered Feb 17, 2020 at 10:41
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I tried both. I've created a new small project to try it out and it all works as it should (both solutions you provided). I'm trying to identify the problem in my other project now. Thank you.
It worked when I set Visual studio "Conformance Mode" setting to "No"
0

It worked when I set Visual studio "Conformance Mode" setting to "No"

answered Feb 17, 2020 at 12:21

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.