I am trying to implement a variadic function. I searched the web and ended up finding out that most examples handle only one type of arguments (for example calculating average of many integers). Im my case the argument type is not fixed. It can either involve char*, int or both at the same time. Here is the code i ended up with :
void insertInto(int dummy, ... ) {
int i = dummy;
va_list marker;
va_start( marker, dummy ); /* Initialize variable arguments. */
while( i != -1 ) {
cout<<"arg "<<i<<endl;
/* Do something with i or c here */
i = va_arg( marker, int);
//c = va_arg( marker, char*);
}
va_end( marker ); /* Reset variable arguments. */
Now this would work okay if i only had to deal with integers but as you see i have a char* c variable in comments which i would like to use in case the argument is a char*.
So the question is, how do I handle the returned value of va_arg without knowing if it is an int or a char* ?