Skip to main content
added 4 characters in body; edited tags; edited title
Source Link
Shafik Yaghmour
  • 159.8k
  • 44
  • 466
  • 778

Unknown number of arguments in C++ function

I've got the class member:

LineND::LineND(double a ...) { coefficients.push_back(a); va_list arguments; va_start(arguments, a); double argValue; do { argValue = va_arg(arguments, double); coefficients.push_back(argValue); }while(argValue != NULL); // THIS IS A PROBLEM POINT! va_end(arguments); } 

I don't know how many arguments will be used. I need to take each argument and put it into the vector called coefficients. How should I do that? I understand, that the statement while(argValue != NULL) is not correct in this case. I can't use for example this signature:

LineND::LineND(int numArgs, double a ...) 

to change the condition like this:

while(argValue != numArgs); 

The point is I can't change the signature of the method. Need to resolve this problem another way.

Unknown number of arguments in C++ function

I've got the class member:

LineND::LineND(double a ...) { coefficients.push_back(a); va_list arguments; va_start(arguments, a); double argValue; do { argValue = va_arg(arguments, double); coefficients.push_back(argValue); }while(argValue != NULL); // THIS IS A PROBLEM POINT! va_end(arguments); } 

I don't know how many arguments will be used. I need to take each argument and put it into the vector called coefficients. How should I do that? I understand, that the statement while(argValue != NULL) is not correct in this case. I can't use for example this signature

LineND::LineND(int numArgs, double a ...) 

to change the condition like this

while(argValue != numArgs); 

The point is I can't change the signature of the method. Need to resolve this problem another way.

Unknown number of arguments in function

I've got the class member:

LineND::LineND(double a ...) { coefficients.push_back(a); va_list arguments; va_start(arguments, a); double argValue; do { argValue = va_arg(arguments, double); coefficients.push_back(argValue); }while(argValue != NULL); // THIS IS A PROBLEM POINT! va_end(arguments); } 

I don't know how many arguments will be used. I need to take each argument and put it into the vector called coefficients. How should I do that? I understand, that the statement while(argValue != NULL) is not correct in this case. I can't use for example this signature:

LineND::LineND(int numArgs, double a ...) 

to change the condition like this:

while(argValue != numArgs); 

The point is I can't change the signature of the method. Need to resolve this problem another way.

Post Closed as "exact duplicate" by Shafik Yaghmour, Kate Gregory, CloudyMarble, tkanzakic, Sindre Sorhus
Source Link
Sergey Shafiev
  • 4.4k
  • 4
  • 29
  • 37

Unknown number of arguments in C++ function

I've got the class member:

LineND::LineND(double a ...) { coefficients.push_back(a); va_list arguments; va_start(arguments, a); double argValue; do { argValue = va_arg(arguments, double); coefficients.push_back(argValue); }while(argValue != NULL); // THIS IS A PROBLEM POINT! va_end(arguments); } 

I don't know how many arguments will be used. I need to take each argument and put it into the vector called coefficients. How should I do that? I understand, that the statement while(argValue != NULL) is not correct in this case. I can't use for example this signature

LineND::LineND(int numArgs, double a ...) 

to change the condition like this

while(argValue != numArgs); 

The point is I can't change the signature of the method. Need to resolve this problem another way.