Determine Size of a va_list

I am trying to make a function that accepts a variable amount of character sequences without having to specify how many arguments are being passed when I call the function. Here is the basic idea:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void Alphabetize(char *text, ...)
{
   va_list list;
   va_start(list, text);

   std::vector<std::string> chunks;

   for (int n=0; n < list.size(); n++)
   {
      std::string chunk = va_arg(list, char*);
      chunks.push_back(chunk);
   }

   va_end(list);

   std::string result;
   //alphabetize chunks and print each one out on its own line
  
   return result;
}

int main()
{
   std::cout << Alphabetize("Wood","Cow","Plastic","Random");
   return 0;
}


Cow
Plastic
Random
Wood



There isn't actually a size() method with va_list, but I need something similar. Is it even possible to make a function like Alphabetize()? I don't want to have to specify the number of arguments in the call by saying

AlphabetizeAndCombine(4,"Wood","Cow","Plastic","Random")

or something like that.
The only way is to do just that - somehow specify the size as one of the parameters. You can't ask "is this memory a parameter to my function or something else" without having other memory to answer and say yes or no. Sometimes this is done internally (virtual inheritance), and other times it needs to be done by the programmer, which is this case. Although, there may be some assembly for it - I don't know.
Last edited on
Topic archived. No new replies allowed.