Variable arguments, different types?

hello,

can anybody tell me if stdarg.h supports variable list of arguments having different types? I saw a lot of examples where a function takes variable number of integers and finds the max of it but can we have functions accepting different types of variable number of arguments. If yes, can someone give a small example?
Thanks

Suraj
Last edited on
Hi...
Is this what you are expecting????????...


// Function template example.

#include <iostream>
using namespace std;

// This is a function template.

template <class X> void swapargs(X &a, X &b)
{
X temp;
temp = a;
a = b;
b = temp;
}

int main()
{
int i=10, j=20;
double x=10.1, y=23.3;
char a='x', b='z';

cout << "Original i, j: " << i << ' ' << j << '\n';
cout << "Original x, y: " << x << ' ' << y << '\n';
cout << "Original a, b: " << a << ' ' << b << '\n';

swapargs(i, j); // swap integers
swapargs(x, y); // swap floats
swapargs(a, b); // swap chars

cout << "Swapped i, j: " << i << ' ' << j << '\n';
cout << "Swapped x, y: " << x << ' ' << y << '\n';
cout << "Swapped a, b: " << a << ' ' << b << '\n';

return 0;
}
Yes, cstdarg supports any kind of argument types, just think about the printf and scanf family.
http://www.cplusplus.com/reference/clibrary/cstdarg/
Whatever it is you are doing, there is surely a better way to do it.

What are you trying to accomplish with this?
Topic archived. No new replies allowed.