I am trying to implement a variational function. I searched the Internet and found that most examples handle only one type of argument (e.g. calculating the average of integers). In my case, the type of the argument is not fixed. It can include either char *, int, or both at the same time. Here is the code I ended up in:
void insertInto(int dummy, ... ) {
int i = dummy;
va_list marker;
va_start( marker, dummy );
while( i != -1 ) {
cout<<"arg "<<i<<endl;
i = va_arg( marker, int);
}
va_end( marker );
Now this will work if I only need to deal with integers, but as you can see, I have the variable char * c in the comments, which I would like to use if the argument is char *.
So the question is how to handle the return value of va_arg without knowing whether it is int or char *?
source
share