数量不定的模板函数
void print()
{
}
template <typename T,typename... Types>
void print(const T& firstArg,const Types& arges)
{
cout<<firstArg<<endl;
print(args...);
}
调用举例
print(4.5,42,“hello”);
就可以准确输出每个参数。
参数不定的模板参数的作用就是可以帮助我们实现一些递归,但是需要注意的是varidic templates每次使用都需要写一个空函数(函数重载),这样最后一次递归调用的时候就不会报错。