Code:
// Lop Ma tran
template <class Ty> class Matrix
{
private:
int NumRow;
int NumCol;
Ty** Array;
public:
Matrix(int m=0, int n=0)// Khoi tao la ma tran co cac phan tu tren
{ // duong cheo chua phan tu [0][0]=1, con lai =0
NumRow=m;
NumCol=n;
Array =new Ty*[NumRow];
for(int i=0; i<NumRow; i++) Array[i]=new Ty[NumCol];
for(i=0; i<NumRow; i++)
for(int j=0; j<NumCol; j++)
{
if (i==j) Array[i][j]=1;
else Array[i][j]=0;
}
}
//------
Matrix(Matrix& ma) // Ham thiet lap sao chep
{
int i,j;
NumRow=ma.NumRow;
NumCol=ma.NumCol;
Array =new Ty*[NumRow];
for(i=0; i<NumRow; i++) Array[i]=new Ty[NumCol];
for(i=0; i<NumRow; i++)
for(j=0; j<NumCol; j++)
{
Array[i][j]=ma.Array[i][j];
}
}
//------
~Matrix()
{
for(int i=0; i<NumRow; i++) delete Array[i];
delete Array;
}
void input(char Name[]); // Nhap Ma tran
void output(); // In cac phan tu cua Vector
Matrix& operator= (Matrix& ma);
void setMatUnit(int rank); // Tao ma tran don vi (ma tran vuong)
Ty getEle(int RowNum, int ColNum); // Lay 1 phan tu
void setEle(int RowNum, int ColNum, Ty newvar); // Thay doi gia tri cua 1 phan tu
Vector<Ty> getRow(int RowNum); // Lay ra mot hang
Vector<Ty> getCol(int ColNum); // Lay ra mot cot
Matrix getMat(int Row1,int Col1, int Row2, int Col2);//Lay Ma tran con: Row1<Row2 ; Col1<Col2
Matrix chaRow(int RowNum, Vector<Ty>& vt); // Change Row
Matrix chaCol(int ColNum, Vector<Ty>& vt); // Change Column
Matrix delRow(int RowNum); // delete Row
Matrix delCol(int ColNum); // delete Col
Matrix perRow(int Row1, int Row2); // permute Row : doi cho 2 hang
Matrix perCol(int Col1, int Col2); // permute Col : doi cho 2 cot
int getNumRow();//Lay so hang
int getNumCol();//Lay so cot
Matrix operator+ (Matrix& ma);
Matrix operator- (Matrix& ma);
Matrix operator* (Matrix& ma);
Vector<Ty> operator* (Vector<Ty> vt);
Matrix operator* (Ty k);
Matrix traMat(); // transpose Matrix : chuyen vi
Ty det(int rank); // Tinh dinh thuc , rank : cap cua matran vuong
Matrix inv(int rank); // inverse: ma tran nghich dao
//Cac ham su dung khi mo phong
void setTran(Ty dx, Ty dy, Ty dz); //Thiet lap ma tran tinh tien thuan nhat
void setRotX(Ty angle); //Thiet lap ma tran thuan nhat quay quanh truc X
void setRotY(Ty angle); //Thiet lap ma tran thuan nhat quay quanh truc Y
void setRotZ(Ty angle); //Thiet lap ma tran thuan nhat quay quanh truc Z
operator double* (); //Toan tu ep kieu ma tran ve kieu con tro (mang)
operator float* ();
operator int* ();
};
đây là lớp matrix .Em muôn xây dựng một mảng để lưu các ma trận cấp 4x4
Vậy bây giờ em khai báo một mảng matrix<double>p[16] ,rồi sau đó p[0]=matrix<double>(4,4).Theo các bác em làm như vậy có vấn đề gì ko?ma sao no cu báo lỗi"array not allowce size 0"