A
Alan
I have a couple of questions about using a variable number of
arguments in a function call (...). The context is that I have some
mathematical functions I created. I currently pass them a pair of
numbers (doubles), and the functions only work in one dimension. I
would ideally like to extend them to work in N dimensions, which means
I want to pass some undefined number of pairs of arguments. I will
loop through the N arguments to do the math in N dimensions.
1. Some consider using a variable number of arguments unsafe, due to
type checking concerns. So, is there a another but simple way to
extend the function so I can pass it N pairs of numbers? Or would you
simply recommend heavy error checking in the functions?
2. Can the arguments in a variable number of arguments call to a
function be class templates? As in:
template <class T>
T do_math (class T, . . .)
{
. . .
}
Thanks in advance,
Alan
arguments in a function call (...). The context is that I have some
mathematical functions I created. I currently pass them a pair of
numbers (doubles), and the functions only work in one dimension. I
would ideally like to extend them to work in N dimensions, which means
I want to pass some undefined number of pairs of arguments. I will
loop through the N arguments to do the math in N dimensions.
1. Some consider using a variable number of arguments unsafe, due to
type checking concerns. So, is there a another but simple way to
extend the function so I can pass it N pairs of numbers? Or would you
simply recommend heavy error checking in the functions?
2. Can the arguments in a variable number of arguments call to a
function be class templates? As in:
template <class T>
T do_math (class T, . . .)
{
. . .
}
Thanks in advance,
Alan