variable parameters

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void vMerge(vector<int> *dest, vector<int> v2, ...)
{
	va_list param;
	va_start(param,v2);

        // dest <- v2
	dest->insert(dest->end(),v2.begin(),v2.end());

	vector<int> arg;
	while(param != NULL)  // how do I stop it when it's at last parameter
	{
		arg = va_arg(param,vector<int>);
		dest->insert(dest->end(),arg.begin(),arg.end());
	}

	va_end(param);
}


I have a function that copies multiple vectors into one vector dest, my problem right now is to stop the while loop from continuing after the last parameter. Any help is appreciated.
You can't know how many args were pushed onto the stack. You have to communicate it somehow.

A standard alternative is to overload on the number of parameters.
Also, don't use variadic argument lists with non-POD types.
Topic archived. No new replies allowed.