#include <iostream>

// 可变模板参数
// 此例:可以构造可变数量,可变类型的函数输入。
// 摘自:https://www.cnblogs.com/qicosmos/p/4325949.html ///////////////////////////// using namespace std;
//递归终止函数
void print()
{
cout << "empty" << endl;
} //展开函数
template <typename T, typename... Args>
void print(T head, Args... rest) // Args... 是可变模板参数的写法
{
auto num_of_rest_inputs = sizeof...(rest); cout << "parameter " << head << endl;
print(rest...);
} ///////////////////////////// int main(void)
{
print(1, 2, 3.6, 4);
return 0;
}

  

05-11 20:11