G
Guest
How to call a function with variable argument list from another function
again with variable argument list?
Example :
double average ( int num, ... );
double AFunct1 ( int num, ... );
double AFunct2 ( int num, ... );
double average ( int num, ... )
{
va_list arguments; // A place to store the list of
arguments
double sum = 0;
va_start ( arguments, num ); // Initializing arguments to store
all values after num
for ( int x = 0; x < num; x++ ) // Loop until all numbers are added
sum += va_arg ( arguments, double ); // Adds the next value in argument
list to sum.
va_end ( arguments ); // Cleans up the list
return sum / num; // Returns some number (typecast
prevents truncation)
}
double AFunct2 ( int num, ... )
{
HOW to call "avarge" here? <----???????
}
double AFunct1 ( int num, ... )
{
HOW to call "AFunct2" here? <----???????
}
main ()
{
double d = AFunct1(5, 2, 3, 4, 123.456, 78);
cout << d;
}
again with variable argument list?
Example :
double average ( int num, ... );
double AFunct1 ( int num, ... );
double AFunct2 ( int num, ... );
double average ( int num, ... )
{
va_list arguments; // A place to store the list of
arguments
double sum = 0;
va_start ( arguments, num ); // Initializing arguments to store
all values after num
for ( int x = 0; x < num; x++ ) // Loop until all numbers are added
sum += va_arg ( arguments, double ); // Adds the next value in argument
list to sum.
va_end ( arguments ); // Cleans up the list
return sum / num; // Returns some number (typecast
prevents truncation)
}
double AFunct2 ( int num, ... )
{
HOW to call "avarge" here? <----???????
}
double AFunct1 ( int num, ... )
{
HOW to call "AFunct2" here? <----???????
}
main ()
{
double d = AFunct1(5, 2, 3, 4, 123.456, 78);
cout << d;
}