//matrix.h
#ifndef MATRIX_H_INCLUDED
#define MATRIX_H_INCLUDED
#include <iostream>
using namespace std;
template <typename T>
class Matrix
{
private:
int cols, rows;
T *pdata;
public:
void AddVal(T a);
bool AddMatrix(Matrix<T> m2);
Matrix<T> MultiMatrix(Matrix<T> m2);
Matrix<T> operator * (Matrix<T> &m2);
Matrix()
{
cols=1, rows=1;
pdata=new T [1];
*pdata=0;
}
Matrix(T v)
{
cols=1, rows=1;
pdata=new T [1];
*pdata=v;
}
Matrix(int rs, int cols, T Arr[], int arrsize)
{
this->cols=cols;
rows=rs;
pdata=new T [rows*cols];
int i, n=rows*cols;
for(i=0;i<n;i++)
{
*(pdata+i)=0;
}
for(i=0;i<arrsize;i++)
{
*(pdata+i)=Arr[i];
}
}
~Matrix(){delete []pdata;}
template <typename T1>
friend ostream & operato
使用C++模板实现矩阵的运算
最新推荐文章于 2022-04-05 21:14:41 发布