[gameprogrammer] c++ template problem

Hi,

I am trying to make a template class for math vectors.

template <typename T, int N>
class Vect
{
private:
   T V[N];
...
}

I wrote a few functions and operators which work, but I have a problem with one of the constuctors.

The c'tor should get the values of the coordinates, but because of the template parameter N, I do not know
how many parameter the c'tor should get. I tried that:

   Vect<T,N>(T v0, T v1, ...) {
       va_list params;

       V[0] = v0;
       V[1] = v1;

       va_start(params, v1);
       for (int i=2; i<N; i++)
           V[i] = (T)va_arg(params, T);
       va_end(params);
   }

The program holds with segmentation fault when this function steps into the for loop. I do not see any reason why dous it crash, I searched the net and found almost the same functions as examples for the usage of variable function parameters.

The second thing I tried is inheritance like that:

template <typename T>
class vect3 : public Vect<T, 3>
{
public:
   vect3(T v0, T v1, T v2) : Vect<T, 3>()
   {
       T v[3] = {v0, v1, v2};
       (*this) = v;
   }
};
It complains, that there is no operator= that match, but there is one in Vect<T, N>:
   void operator=( const T* v ) {
       for (int i=0; i<N; i++) V[i] = v[i];
   }

Has anyone an idea what do I wrong?

(sorry for the poor english)
Thanks,
fenor

---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: