In c & c++, this can be achieved by something called variable arguments. Note that for varargs, you do need to provide atleast one argument which is the number of strings, at the time of invoking the function.
A variable argument facilitates the passing of multiple arguments, without actually knowing the number of arguments to pass.
For this, you can include stdarg.h. This gives you the data type: va_list, and associated functions:
#include <cstdarg>
#include <iostream>
using namespace std;
void check ( int num, ... )
{
va_list arguments; //a place to store the arguments values
va_start ( arguments, num ); // Initializing arguments to store all values after num
for ( int x = 0; x < num; x++ ) { // Loop until all numbers are added
cout << va_arg ( arguments, string ); // Prints the next value in argument list to sum.
}
va_end ( arguments ); // Cleans up the list
}
void MyClass::go()
{
check(3,"string1","string2","string3");
}
num is the number of arguments, that you'll provide.
va_start populates the va_list with the arguments (in this case the strings) that you provide.
va_arg() is used as to access those arguments in the list.
Finally, va_end() is used for cleaning up the va_list.