H
hrmadhu
Hi,
I am trying to write a template for an array which I can use to
create multi-dimensional matrices as
// A 10x10 matrix with each element initialized to 0
Array< Array<int> > Matrix (10,0);
// A 5x5x5 3-dimensional matrix with each element initialized to 1
Array< Array <Array<int> > > Matrix3D (5,1);
// A 15x15x15x15 4-dimensional matrix with each element initialized to
10
Array< Array< Array< Array<int> > > > Matrix4D(15,10);
The code for the array class is as follows:
template < class T> class Array
{
private:
T* _data;
public:
Array(int Size, T Initializer)
{
int i;
_data= new T[Size];
for(i=0;i<Size;i++)
{
_data=Initializer;
/****************************************************
/***** OR SHOULD I USE
_data=T(Initializer);
/****************************************************/
}
}
};
Now if I try and declare a matrix as
Array< Array<int> > Matrix (10, 10 );
the compiler cribs as it expects an initializer of type Array<int> for
the Initializer when it does
_data=T(Initializer);
Can someone please help me out ? how do I write a template for an
Array such that I can easily extend it to multidimensions
thanks a lot in advance.
Regards,
Madhu
I am trying to write a template for an array which I can use to
create multi-dimensional matrices as
// A 10x10 matrix with each element initialized to 0
Array< Array<int> > Matrix (10,0);
// A 5x5x5 3-dimensional matrix with each element initialized to 1
Array< Array <Array<int> > > Matrix3D (5,1);
// A 15x15x15x15 4-dimensional matrix with each element initialized to
10
Array< Array< Array< Array<int> > > > Matrix4D(15,10);
The code for the array class is as follows:
template < class T> class Array
{
private:
T* _data;
public:
Array(int Size, T Initializer)
{
int i;
_data= new T[Size];
for(i=0;i<Size;i++)
{
_data=Initializer;
/****************************************************
/***** OR SHOULD I USE
_data=T(Initializer);
/****************************************************/
}
}
};
Now if I try and declare a matrix as
Array< Array<int> > Matrix (10, 10 );
the compiler cribs as it expects an initializer of type Array<int> for
the Initializer when it does
_data=T(Initializer);
Can someone please help me out ? how do I write a template for an
Array such that I can easily extend it to multidimensions
thanks a lot in advance.
Regards,
Madhu