#include<iostream>
using namespace std;
template<typename Head, typename ...Tail>
double Max(Head first, Tail... rest)
{
double Maxnum = 0;
Maxnum = Max(rest...);
if (Maxnum < first)
Maxnum = first;
return Maxnum;
}
template<typename Head>
double Max(Head first)
{
return first;
}
int main()
{
cout << Max(1, 3, 3.4, 5.1, 1.5, 99.9) << '\n';
system("pause");
return EXIT_SUCCESS;
}
注意:上面的rest...
表示参数展开,也就是说将这个参数包展开然后当做参数传进去。
输出:
99.9
请按任意键继续. . .
源自:
https://blog.csdn.net/y1196645376/article/details/51416043
标签:...,Maxnum,递归,Max,rest,C++,double,模板,first From: https://www.cnblogs.com/huvjie/p/18535577