|
//***提建议,我觉得可以优化一下(虽然我也不知道对不对):
//这是你的一部分
class Matrix
{
private:
int row;
int col;
public:
int ** p;
Matrix(int n);
Matrix(int m ,int n);
Matrix(const Matrix& A);
~Matrix();
Matrix& operator= (const Matrix& A);
int GetRow() const {return row;}
int GetCol() const {return col;}
friend std::ostream& operator<< (std::ostream& os ,const Matrix& A);
friend std::istream& operator>> (std::istream& is , Matrix& B);
};
Matrix operator* (const Matrix& A ,const Matrix& B);
Matrix::Matrix(int n)
{
row = n;
col = n;
p=new int * [row];
for(int i = 0 ; i < col ; i++)
p[i] = new int [col];
for(i = 0 ; i < row ;i++)
for(int j = 0 ; j < col ; j++)
*(*(p+i)+j) = 0;
}
Matrix::Matrix(int m ,int n)
{
row = m;
col = n;
p = new int * [row];
for(int i = 0 ; i < row ; i++)
p[i] = new int [col];
for(i = 0 ; i < row ;i++)
for(int j = 0 ; j < col ; j++)
*(*(p+i)+j) = 0;
}
Matrix::Matrix(const Matrix& A)
{
row = A.row;
col = A.col;
p = new int * [row];
for(int i = 0 ; i < row ; i++)
p[i] = new int [col];
for(i = 0 ; i < row ;i++)
for(int j = 0 ; j < col ; j++)
*(*(p+i)+j) = *(*(A.p+i)+j);
}
Matrix::~Matrix()
{
for(int i = 0 ; i < row ; i++)delete [] p[i]; delete [] p;
} |
|