关于矩阵运算的若干问题

来源:互联网 发布:华为 人工智能 编辑:程序博客网 时间:2024/05/27 06:51
如果写好了向量类,怎样才可以有效地利用已有资源完成矩阵类呢?
经思考,我的初步想法是采用行向量与列向量之间的转换与运算来实现矩阵类的功能。
如有以下向量类:
class Vector
{
public:
     Vector(int=1);
    Vector(IntReal*,int);
    Vector(Vector&);
    ~Vector();
    IntReal&operator[](int i);  //重载[]运算符  ,返回类型   IntReal*
    int operator()();                //重载()运算符,返回  len
    Vector& operator=(Vector&);
    friend Vector operator+(Vector&,Vector&);
    friend ostream& operator<<(ostream& output,Vector&);
    friend istream& operator>>(istream& input,Vector&);
private:
     IntReal *v;      //has class  IntReal          IntReal是一个自定义的实数类,相当兼容了int与double的性质
     int len;
};
 
继承的方式可以是以下方案:
class Matrix:public Vector{
public:
 Matrix(int=1,int=1);
 Matrix(Matrix&);
 Matrix(Vector*,int=1,int=1);
 friend ostream& operator<<(ostream& output,Matrix&);
 friend istream& operator>>(istream& input,Matrix&);
 Matrix& operator=(Matrix& );
 friend Matrix operator-(Matrix&,Matrix&);
 friend Matrix operator+(Matrix&,Matrix&);
protected:
 Vector* Row_vector;        //行向量
 Vector* Column_vector;     //列向量
 int Row_num,Column_num;
};
 
 
问题是,我不知道怎么实现矩阵转置?
还有,经测试,析构函数很难写,我写的都会报内存错误。不知有什么更好的方法呢?
 
 
原创粉丝点击