If you have a function which can accept a variable number of arguments, how can you find out how many arguments were passed to it?
Printable View
If you have a function which can accept a variable number of arguments, how can you find out how many arguments were passed to it?
Either manually (passing number of arguments as an argument), or by fetching argument by argument until you come across a "known value" that is used to mark the end of arguments (ie NULL), or if the arguments are all of the same type, you can use a vector and use its .size() method.
Incidentally, are you sure that you need variable argument lists in the first place?
Awesome, thanks. And thanks for replying with the "safe delete" function in my other thread, too!
Unless the function expects different types, in order. But generally, you are right, of course.
yes, that is true if there is an assumed repeating pattern to the types passed. however it may well still be preferable, even if arguably marginally less convenient, to pass a vector of structs.
just yesterday i made a polynomial function that uses a variable argument constructor, where the constructor arguments go: unsigned int order, int exp1,double coeff1,...int expn,double coeffn
and what did i end up having to do immediately thereafter?
declaringwithin the body of polynomial to store the data in a vector. in then end it would have been vetter to just pass a vector<polynomial::ecpair>Code:struct ecpair{int exp;double coeff;}
the only thing i can really see variable argument functions providing unique functionality is is where the first argument is a typelist, as then there need be no pattern, but then my compiler doesn't match the function so it doesn't work anyway. :\