1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
// overloaded function with 2 args
double max_of( int a, int b ) { return a<b ? b : a ; }
// overloaded function with 3 args
int max_of( int a, int b, int c )
{
// call overloaded function with 2 args (twice)
return max_of( a, max_of(b,c) ) ;
}
// overloaded function with 4 args
int max_of( int a, int b, int c, int d )
{
// call overloaded function with 3 args, then overloaded function with 2 args
return max_of( a, max_of(b,c,d) ) ;
}
int main()
{
std::cout << max_of( 23, 45, 42, 17 ) << '\n' ; // 45
}
|