CVector(X first, ...)
{
array = new X[size];
array[0] = first;
va_list args;
va_start(args, first);
for(int i(1); i < size; i++)
array = va_arg(args, X);
va_end(args);
}
template and va_arg
Hi everyone,
I have this function in a template class:
And when I use it like this : CVector<double> V(1, 2, 3), it does not recognise that 1, 2, and 3 are doubles and it mess up the values... To make it work I have to do : CVector<double> V((double)1, (double)2, (double)3)
I don't know if I'm clear enough...
Do you have any ideas?
Thanks in advance
Quote:Original post by ju
Hi everyone,
I have this function in a template class:
*** Source Snippet Removed ***
And when I use it like this : CVector<double> V(1, 2, 3), it does not recognise that 1, 2, and 3 are doubles and it mess up the values... To make it work I have to do : CVector<double> V((double)1, (double)2, (double)3)
I don't know if I'm clear enough...
Do you have any ideas?
Thanks in advance
use 1. 2. and 3.
Also, just as a recommendation, do not use "..." as it will not work with non-pod types.
Really not a good idea. If you don't provide enough arguments, it won't work, but you won't know it isn't working.
size appears to be a constant. If it is, you should use a constructor with the maximum number of arguments, all with default values.
size appears to be a constant. If it is, you should use a constructor with the maximum number of arguments, all with default values.
Thanks for your answers...
I think I'll change of methode...
for size : the class was in fact :
template <class X, int size> CVector
so size is not defined before the construction and then it was not possible to make a constructor with default values...
Polymorphic OOP : What are "non-pod" types?
Thanks in advance
I think I'll change of methode...
for size : the class was in fact :
template <class X, int size> CVector
so size is not defined before the construction and then it was not possible to make a constructor with default values...
Polymorphic OOP : What are "non-pod" types?
Thanks in advance
Quote:Original post by Fruny
Plain Old Data
"POD (Plain Old Data) and Non–POD Objects"
Thank you very much Fruny!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement