Let's say I have a matrix template class that will work on matrices of any data type (not any size though since concatenation is diff for diff sizes). In the ctor I need to set the matrix to the identity matrix or:
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Code:
template<class Data_Type> class Matrix
{
Data_Type mdata[4][4];
public:
Matrix(void);
};
template<class Data_Type> Matrix<Data_Type>::Matrix(void)
{
mdata[0][0]=<Data_Type>1;
mdata[0][1]=<Data_Type>0;
mdata[0][2]=<Data_Type>0;
mdata[0][3]=<Data_Type>0;
mdata[1][0]=<Data_Type>0;
mdata[1][1]=<Data_Type>1;
mdata[1][2]=<Data_Type>0;
mdata[1][3]=<Data_Type>0;
mdata[2][0]=<Data_Type>0;
mdata[2][1]=<Data_Type>0;
mdata[2][2]=<Data_Type>1;
mdata[2][3]=<Data_Type>0;
mdata[3][0]=<Data_Type>0;
mdata[3][1]=<Data_Type>0;
mdata[3][2]=<Data_Type>0;
mdata[3][3]=<Data_Type>1;
}
Will <Data_Type> typecast the 1 and 0 to the correct data type? Or should I place the Data_Type within a typecast like:
matrix[0][0]=(Data_Type)1;
If this is the wrong way to do this, how would I go about initializing the array with values of the correct data type?
Or is this cast unecessary since mdata is already of type Data_Type. Will the compiler automatically cast the values to the correct type?
I know that instead of using an array I could use a class from the standard class library, but I chose not to.