Original Post
I'm writing a template vector class and I would like to do stuff like:
TVector<double,3> v1(1.0, 2.0, 3.0); TVector<int,2> v2(12, 14);This would require a constructor that has a number of arguments equal to the size of the vector. As far as I know, this cannot directly be done with templates. So I tried the following:
template<typename t_type,unsigned int t_dimension>
class TVector
{
protected:
t_type m_components[t_dimension];
public:
TVector(const t_type array[t_dimension])
{
for(unsigned int k=0;k<t_dimension;++k)
{
m_components[k] = array[k];
}
}
}
I hoped that would make it possible to write stuff like:
TVector<double,3> v1( { 1.0, 2.0, 3.0 } );
TVector<int,2> v2( { 12, 14 } );
Unfortunately, this doesn't work either. Is there a general (preferably clean) way to solve this? Or do I have to stick with
individual assignment of components after creation of the vector.
Thanks.
mod: trying to make those template-parameters visible :-)
[edited by - Koen on December 29, 2003 7:09:25 PM]