From: Benjamin R. <Ben...@ep...> - 2003-12-13 17:35:48
|
Hi Don, "Don HO" <do...@al...> writes: > void FileDialog::setExtFilter(const char *extText, const char *ext, ...) > { > std::string extFilter = extText; > > va_list pArg; > va_start(pArg, extText); > > [...] > > What did I do wrong? If the documentation that you have for va_start() isn't clear about this, you should throw away that documentation. My man page here says: The parameter last is the name of the last parameter before the variable argument list, i.e., the last parameter of which the calling function knows the type. In your case that would be the parameter "ext". Using "extText" instead is invalid. Note that in C++ you should really just use optional parameters or overloading instead, because these techniques provide type safety, automatic type conversion and the ability to use objects and references. Also callers do not need to terminate the varargs list in anyway than. Just use as many optional parameters as you maximally expect. void myvarfunc(const char *extText, const char *s1 = NULL, const char *s2 = NULL, const char *s3 = NULL, const char *s4 = NULL, const char *s5 = NULL, const char *s6 = NULL, const char *s7 = NULL, const char *s8 = NULL) { const char *params[] = {s1, s2, s3, s4, s5, s6, s7, s8}; for( int i=0; i < sizeof(params)/sizeof(params[0]) && NULL != params[i]; ++i ) { .... do something with params[i] } } benny |