class Matrix:public MATRIX
{
public:
Matrix():MATRIX(){}
Matrix( int c, int r ):MATRIX(c,r){}
Matrix( const Matrix& m){ *this = m; }
const Matrix& operator+=( const Matrix& m );
const Matrix& operator-=( const Matrix& m );
const Matrix& operator*=( const Matrix& m );
const Matrix& operator/=( const Matrix& m );
};
bool operator==( const Matrix& lhs, const Matrix& rhs ); // 重载操作符==
bool operator!=( const Matrix& lhs, const Matrix& rhs ); // 重载操作符!=
const Matrix operator+( const Matrix& lhs, const Matrix& rhs ); // 重载操作符+
const Matrix operator-( const Matrix& lhs, const Matrix& rhs ); // 重载操作符-
const Matrix operator*( const Matrix& lhs, const Matrix& rhs ); // 重载操作符*
const Matrix operator/( const Matrix& lhs, const Matrix& rhs ); // 重载操作符/
const double det( const Matrix& m ); // 计算行列式
const double det( const Matrix& m, int start, int end ); // 计算子矩阵行列式
const Matrix abs( const Matrix& m ); // 计算所有元素的绝对值
const double max( const Matrix& m ); // 所有元素的最大值
const double max( const Matrix& m, int& row, int& col); // 所有元素中的最大值及其下标
const double min( const Matrix& m ); // 所有元素的最小值
const double min( const Matrix& m, int& row, int& col); // 所有元素的最小值及其下标
const Matrix trans( const Matrix& m ); // 返回转置矩阵
const Matrix submatrix(const Matrix& m,int rb,int re,int cb,int ce); // 返回子矩阵
const Matrix inverse( const Matrix& m ); // 计算逆矩阵
const Matrix LU( const Matrix& m ); // 计算方阵的LU分解
const Matrix readMatrix( istream& in = std::cin ); // 从指定输入流读入矩阵
const Matrix readMatrix( string file ); // 从文本文件读入矩阵
const Matrix loadMatrix( string file ); // 从二进制文件读取矩阵
void printMatrix( const Matrix& m, ostream& out = std::cout ); // 从指定输出流打印矩阵
void printMatrix( const Matrix& m, string file); // 将矩阵输出到文本文件
void saveMatrix( const Matrix& m, string file); // 将矩阵保存为二进制文件
#endif
这是.h文件我想在另一个.cpp文件中调用const Matrix readMatrix( istream& in = std::cin ); 这个函数,不知道怎么写?麻烦大神帮我一下,我真是个小白。。
试试:
void main()
{
Matrix a;
a=readMatrix();
}
哦哦 我刚刚经过百般尝试发现在我的Matrix.h的实现文件Matrix.cpp中使用下面那几行就可以实现,但是我想在test.cpp中也调用这个函数,我是include了.h文件 一直报错,是不是我也得加上include"Matrix.cpp"呢?
int main()
{
Matrix matrix;
matrix = readMatrix(cin);
//matrix.printMatrix();
cout << matrix.rows() << endl;
return 0;
}