123456789101112131415161718192021222324252627282930313233343536
#include <iostream> #include <cassert> #include <cstdarg> using namespace std; int max(unsigned count, ...) { assert(count > 0); va_list arguments; va_start(arguments, count); int result = va_arg(arguments, int); while(--count > 0) { int arg = va_arg(arguments, int); if (arg > result) result = arg; } va_end(arguments); return result; } int main() { int a(56), b(8), c(66),d(14); cout << max(4 /*number of parameters passed */, a, b, c, d) <<endl; return 0; }