Hey all. Long time no see. Sadly I don't have the time to keep up with these forums like I used to. =( But I had a C++ question and figured the people here could help!
I want to do something like this:
template <typename T, ??? > // <- not sure what should go in the '???'
T* func( ??? )
return new T( ??? );
The idea being, 'func' takes any number of parameters, of any type. And I want all those extra parameters to be forwarded to the constructor of my T object. Similar to what make_unique does.
The end result being:
Foo* p = func<Foo>(1, "whatever", someobj);
// is the same as
Foo* p = new Foo(1, "whatever", someobj);
I never fully wrapped my head around variadic templates, and this is kind of a huge blind spot for me. Does anyone know how to accomplish this?
Last edited on
Perfect. Thanks JLBorges.
Yes I know to use make_unique. I was just giving a simplistic example of what I'm trying to do. My use case here is a bit different. ;)