Answer the question
In order to leave comments, you need to log in
Variable number of parameters and function template
I have a template class that implements a matrix (cells can contain data of different types).
to fill the matrix, the function is used:
void setItems(int _row, int _col, ...){
fieldInitialization(_row, _col);
int argumentNumber = _row * _col;
va_list arguments;
va_start(arguments, argumentNumber);
for (int i = 0 ; i < _row ; i++){
for (int j = 0 ; j < _col ; j++){
tab[i][j] = va_arg(arguments, T);
}
}
va_end(arguments);
}
second parameter of ‘va_start’ not last named argument [enabled by default]
- ‘char’ is promoted to ‘int’ when passed through ‘...’ [enabled by default]
- (so you should pass ‘int’ not ‘char’ to ‘va_arg’)
- if this code is reached, the program will abort
Answer the question
In order to leave comments, you need to log in
It seems to me that there is an error here:
va_start(arguments, argumentNumber);
The second argument to the va_start macro is the last known argument in the function. The compiler even tells you about it.
For example:
int magicFunction(int a, int b, int c, ...) {
va_list args;
va_start(args, c);
//...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question