#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