从右向左哦~ 其实,通过设置断点走一遍就知道了
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class Matrix
{
public:
Matrix(int m,int n):a(m),b(n){}
Matrix(){}
friend Matrix operator + (const Matrix& pre, const Matrix& mat);
Matrix(const Matrix& A){ a=A.a;b=A.b;cout<<"拷贝构造函数被调用"<<endl;}
int getA(){return a;}
int getB(){return b;}
private:
int a,b;
};
Matrix operator + (const Matrix& pre, const Matrix& mat)
{
Matrix M;
M.a=pre.a+mat.a;
M.b=pre.b+mat.b;
return M;
}
int main(int argc, char* argv[])
{
cout<<"start:"<<endl;
Matrix A(1,3);
Matrix B(2,4);
Matrix C=A+B;
cout<<C.getA()<<(C.getB()+1)<<" "<<C.getB()<<endl;
system("pause");
return 0;
}