template<typename...>
struct caller;
template<typename T, typename...Rest>
struct caller<T, Rest...>
{
static void call()
{
create<T>();
caller<Rest...>::call();
}
};
template<>
struct caller<>
{
static void call()
{
}
};
//since you've not mentioned the return type, I'm assuming it to be void
//if it is not void, then I don't know what you're going to return, and HOW!
template<typename...classes>
void createObject(){
caller<classes...>::call();
}
演示:http: //ideone.com/UHY8n
替代方案(较短的版本):
template<typename...>
struct typelist{};
template<typename T, typename ... Rest>
void call(typelist<T,Rest...>)
{
create<T>();
call(typelist<Rest...>());
};
void call(typelist<>) { }
template<typename...classes>
void createObject(){
call(typelist<classes...>());
}
演示:http: //ideone.com/cuhBh