这个程序是你要吗 ?
#include <cstdlib>
#include <cstdarg>
#include <iostream>
using namespace std;
template<typename T>
T _max(uint const n, ...)
{
va_list others;
va_start(others, n);
T max = va_arg(others, T);
for (uint i = 2; i <= n; ++i)
{
T const next = va_arg(others, T);
max = next > max ? next : max;
}
va_end(others);
return max;
}
int main()
{
cout << _max<int>(1u, 1) << endl;
cout << _max<int>(2u, 1, 2) << endl;
cout << _max<double>(3u, 1., 3., 2.) << endl;
cout << _max<double>(5u, 1., 5., 10., 2., 1.) << endl;
}
[
本帖最后由 serious 于 2009-9-20 00:00 编辑 ]