⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrix.h

📁 自己写的矩阵类
💻 H
字号:

#ifndef MATRIX_H_QIHANG
#define MATRIX_H_QIHANG
typedef float MATRIXTYPE;
/*
冯启航 2008年3月15日 写
矩阵类 
推荐模板参数信息为内建型别

*/
#ifdef DLL_FILE_MATRIX
#define DLL_WIN_API_ __declspec(dllexport)
#else
#define DLL_WIN_API_ __declspec(dllimport)
#endif
class DLL_WIN_API_ Matrix
{
public:
	int m_row;//矩阵行数
	int m_col;//矩阵列数
	MATRIXTYPE ** m_data;//矩阵存放数值的地方
public:
	Matrix()//构造函数1
	{
		m_col = 0;
		m_row = 0;
		m_data = NULL;
	}
	Matrix(int row,int col)//构造函数2
	{
		m_row = row;
		m_col = col;
		m_data = new MATRIXTYPE*[m_row];
		int i, j;
		for (i = 0 ; i < m_row ;++i)
		{
			m_data[i] = new MATRIXTYPE[m_col];
		}
		for (i = 0 ; i < m_row ; ++i)
		{
			for (j = 0 ; j < m_col ; ++j)
			{
				m_data[i][j] = (MATRIXTYPE)0;
			}
		}
	}

	~Matrix()//析构函数
	{
		if (m_data != NULL)
		{
			for (int i = 0; i < m_row;i++)
			{
				delete[] m_data[i];
			}
			delete[] m_data;
		}
		m_data = NULL;
	}
	//拷贝构造函数
	Matrix(const Matrix &mat)
	{
		if (this == &mat)
		{
			return ;
		}
		m_row = mat.m_row;
		m_col = mat.m_col;
		m_data = new MATRIXTYPE*[m_row];
		int i, j;
		for (i = 0 ; i < m_row ;++i)
		{
			m_data[i] = new MATRIXTYPE[m_col];
		}
		for (i = 0 ; i < m_row ; ++i)
		{
			for (j = 0 ; j < m_col ; ++j)
			{
				m_data[i][j] = mat.m_data[i][j];
			}
		}
	}
public:
	//重载操作符
	Matrix& operator=(const Matrix &mat);
	Matrix& operator+=(const Matrix &mat); 
	MATRIXTYPE* operator[](int x)const
	{
		return this->m_data[x];		
	};
	Matrix& operator-=(const Matrix &mat);
};


//全局函数
DLL_WIN_API_ const Matrix operator*(const Matrix mat1,const Matrix mat2);
DLL_WIN_API_ const Matrix operator+(const Matrix mat1,const Matrix mat2);
DLL_WIN_API_ const Matrix operator-(const Matrix mat1,const Matrix mat2);

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -