Hi I have a class with a member function that takes a variable number of arguments. The class knows how many arguments to expect once it is instantiated. e.g
class myClass
{
myClass(int num_args){na=num_args;};
private:
int na;
public:
void do_something(int num_args, ...);
}
void myClass::do_something(int num_args, ...)
{
va_list vl;
va_start(vl, num_args);
for(int i=0; i < num_args; i++)
do_anotherthing(va_arg(vl, type));
va_end
}
so i end up calling as follows:
myClass A(5);
myClass B(4);
A.do_something(5, a, b, c, d, e);
B.do_something(4, a, b, c, d);
It seems untidy to me to have to keep specifying the number of arguments i'm passing. What's the best way to get around this? I've considered overloading a bunch of functions, each with n arguments, a macro to put the num_args in for me. But ideally I'd like to be able to define do_something as
void do_something(...);
and somehow get the stdargs stuff to work with the class's num_args rather than a value passed in.
Many thanks for your thoughts.