I have the following structure that lets me bind the virtual functions of ExampleInterfaceClass to a class that implements the virtual functions from ExampleInterfaceClass:
struct ExampleStruct {
ExampleInterfaceClass *instance = nullptr;
ExampleInterfaceClass *(*InstantiateScript)(void);
void (*DestroyScript)(ExampleStruct *);
template <typename T> void Bind(void)
{
InstantiateScript = []()
{
return static_cast<ExampleInterfaceClass *>(new T());
};
DestroyScript = [](ExampleStruct *exampleStruct)
{
delete exampleStruct->instance;
exampleStruct->instance = nullptr;
};
}
};
Now I want to forward variadic arguments from Bind() to the instantiation of the class that implement the interface. I know I have to change the template to the following
template <typename T, typename... T_args> void Bind(T_args &&... args)
But I have trouble to pass the variadic arguments to the instantiation of the class because of the lambda. Without the lambda I think I could use the following:
return static_cast<ExampleInterfaceClass *>(new T(std::forward<T_args>(args)...));
But the compiler tells me that 'args' are not captured.
How can I capture the variadic arguments and forward them?
=? - Sam Varshavchik=? That does a copy. - Anonymous1847std::function. - Sam Varshavchik