请教一道C 关于类的静态多态的问题!

请教一道C 关于类的静态多态的问题! - 故障解答 - 电脑教程网

请教一道C 关于类的静态多态的问题!

日期:2006-06-15   荐:
请教一道C 关于类的静态多态的问题!主题是:类的静态多态编写矩阵类,要求: 1、重载构造函数,形成:指定行列;默认行列;拷贝构造函数; 2、析构函数; 3、为矩阵中的元素利用随机函数设置值; 4、以矩阵的形式打印输出到屏幕; 5、返回行数; 6、返回列数; 7、返回指定行、列的元素值; 8、利用运算符重载实现:矩阵加法、矩阵减法、矩阵乘法(加法用友元方式实现;其余用成员方式进行)注:不能用模板和继承!数居结构的书有!!!写了一部分:#include <iostream>using namespace std;enum{DefaultRow = 8,DefaultCol = 8};class Matrix;const Matrix operator ( const Matrix& lhs, const Matrix& rhs );class Matrix{friend const Matrix operator ( const Matrix& lhs, const Matrix& rhs );public:Matrix( int row = DefaultRow, int col = DefaultCol ):_row( row ),_col( col ),_data( new int[row*col] ){}Matrix(const Matrix &m):_row( m._row ),_col( m._col ){_data = new int[_row*_col];memcpy( _data, m._data, _row*_col*sizeof(int) );}~Matrix(){delete []_data;}int Row()const { return _row; }int Col()const { return _col; }int Value( int i, int j ) const { return _data[i*_col j]; }void print()const;const Matrix operator-( const Matrix& rhs );const Matrix operator*( const Matrix& rhs );private:int _row;int _col;int *_data;};void Matrix::print()const{for( int i = 0; i < _row; i ){for( int j = 0; j < _col; j )cout<<_data[i*_col j]<<" ";cout<<endl;}}不用数据结构!C++书里基本上都有静态多态, 那要模板?gt;>?br>
标签: