初学c++ 两矩阵相加 求助!!!
题目: 有两个矩阵 a 和 b ,均为2行3列。求两个矩阵之和。重载运算符“+”,使之能用于矩阵相加。如:c = a + b。我编的程序如下 请大牛 帮忙改改:
/*
* Array.cpp
*
* Created on: 2010-11-5
* Author: sun
*/
#include <iostream>
using namespace std;
class Complex
{
public:
Complex()
{
int a[2][3] = {{0, 0, 0}, {0, 0, 0}};
}
Complex(int m[2][3])
{
a[2][3] = m[2][3];
}
void display(void);
Complex operator + (Complex&);
private:
int a[2][3];
};
Complex Complex :: operator + (Complex &c1)
{
int temp[2][3];
for (int i=0; i<2; i++)
for (int j=0; i<3; i++)
{
temp[2][3] =(a[i][j] + c1.a[i][j]);
}
return Complex(temp[2][3]);
}
void Complex :: display(void)
{
cout << a[2][3];
}
int main(void)
{
int member1[2][3] = {{1, 1, 1}, {1, 1, 1}};
int member2[2][3] = {{2, 2, 2}, {2, 2, 2}};
Complex a(member1[2][3]), b(member2[2][3]), c;
c = a + b;
c.display();
}