C++输出操作符求值顺序

来源:互联网 发布:华硕网络控制器驱动 编辑:程序博客网 时间:2024/05/21 04:39

从右向左哦~ 其实,通过设置断点走一遍就知道了吐舌头

#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;
}

0 0
原创粉丝点击