文档库 最新最全的文档下载
当前位置:文档库 › c++ Matrix类头文件

c++ Matrix类头文件


/** 矩阵类
*Start at 2012.03.11
*End at
*Author lzz
*Supported by lj
*ps
1,错误类型使用抛出异常
2,下标从(0,0)开始
3,函数名一律小写开始(错误的开始)
*/

#pragma once

#include
using namespace std;

//异常类
class MatException{
public:
enum MatExcepType{OutOfRange,SizeNotMatch,OperateOnEmptyMat,MultplyUnfit,RowNotEqualCol};
MatException(MatExcepType excepType);
//string m_describe;//异常类型文字描述
MatExcepType m_ExcepType;
string getExcepDescribe()const;//只返回先不作输出
};


class Matrix{
private:
int m_row;
int m_col;
double *m_data;
double m_global;//泛行矩阵
bool m_isGlobal;//是否为泛矩阵标志,解释为数乘运算,这个就高级了!!!
public:
//const static double ERR_VALUE;
//构造函数
Matrix();
Matrix(const int row,const int col,const double initValue=0 );
Matrix(const Matrix&orgMat);
Matrix(double global);//泛型
//析构函数
~Matrix();
//赋值
const Matrix& operator=(const Matrix&matrix);//=赋值
//快捷访问
double*operator[](int row)throw (MatException);
const double *operator[](int row)const throw(MatException);

//常规运算
Matrix allAddNumer(double dNum)const;//数加操作

friend Matrix operator+(const Matrix&matL,const Matrix&matR) throw(MatException);
Matrix operator-()const throw(MatException);//求负
friend Matrix operator-(const Matrix&matL,const Matrix&matR) throw(MatException);//减法
friend Matrix operator*(const Matrix&matL,const Matrix&matR) throw(MatException);//乘法

//求转置与逆
Matrix operator ~()const ;//求转置
Matrix operator!() const throw(MatException);//求逆
double getDet()const throw(MatException);//求行列式

//通用小函数
double getGlobalValue()const;
int getRows()const;
int getCols()const;
bool isEmpty()const;
bool isGlobal()const{return m_isGlobal;}
//元素统一赋值
void setElementValue(const double dValue);
void initZero();
//特定位置元素访问
double & at(const int row,const int col) throw (MatException);//读取指定位置数,抛出异常
double at(const int row,const int col)const throw (MatException);//不可更改指定位置数
//匹配检测
bool isSizeMatch(const Matrix&mat)const;//行列是否一样
//display for debug
void coutData()const;
private:
double & insideAt(int row,int col)const;//内部使用的at函数,无抛出异常
};



相关文档