Given a template class:
template<class T>
class Foo
{
public:
void FunctionThatCreatesT()
{
_object = new T;
}
private:
shared_ptr<T> _object;
}
Is it possible to somehow pass a set of constructor parameters for T to Foo (perhaps when Foo is constructed) such that Foo can use them when it creates T? A C++11 only solution is fine (so, variadics are on the table for example).
Exactly that, variadic templates and perfect forwarding via
std::forward.For a listing of how this works, see this excellent answer.
You can emulate a limited version of this in C++03 with many overloaded functions, but.. it’s a PITA.
Also, this is only from memory, so no testing done. Might contain an off-by-one error.