Using a function with variable argument strings
Posted
by wrongusername
on Stack Overflow
See other posts from Stack Overflow
or by wrongusername
Published on 2010-06-06T05:58:50Z
Indexed on
2010/06/06
6:02 UTC
Read the original article
Hit count: 293
I was playing around a bit with functions with variable arguments, and decided to make a function to create vectors with the arguments. My function for creating an int
vector worked...
vector<int> makeIntVector(int numArgs, ...) {
va_list listPointer;
va_start(listPointer, numArgs);
vector<int> made;
for(int a = 0; a < numArgs; a++)
made.push_back(va_arg(listPointer, int));
va_end(listPointer);
return made;
}
but not my function for creating a string
vector:
vector<string> makeStringVector(int numArgs, string something, ...) {
va_list listPointer;
va_start(listPointer, something);
vector<string> made;
for(int a = 0; a < numArgs; a++)
made.push_back(va_arg(listPointer, string));
va_end(listPointer);
return made;
}
which crashes the program. What am I doing wrong?
© Stack Overflow or respective owner