马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 优秀的Aurora 于 2020-4-28 14:05 编辑 #include<iostream>
using namespace std;
class Matrix
{
public:
Matrix();
Matrix(int matrix[3][3]);
Matrix operator + (Matrix& m);
Matrix operator * (Matrix& m);
void display()const;
private:
int m_matrix[3][3];
};
Matrix Matrix::operator + (Matrix& m) {
return Matrix(m);
}
Matrix Matrix::operator * (Matrix& m) {
return Matrix(m);
}
int main(void)
{
int a[3][3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int b[3][3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Matrix m1(a);
Matrix m2(b);
Matrix m3 = m1 + m2;
Matrix m4 = m1 * m2;
m3.display();
cout << "-------------------" << endl;
m4.display();
return 0;
}
|