【发布时间】:2016-03-22 19:47:43
【问题描述】:
我正在用 C++ 制作一个类 Matrix,但在测试中,我发现像
这样的语句cout << M1; //M1 is object of class Matrix
正在工作,但其他人喜欢
cout << M1 + M2; //M1 and M2 of class matrix
给我错误。我关心的重载函数有这些原型:
//for matrix addition
Matrix operator+(Matrix& m)
//for stream insertion operator
ostream& operator<<(ostream& out, Matrix & m)
你们能帮我解决我哪里出错了吗?如果需要,我可以发布实际代码。
【问题讨论】:
-
ostream& operator<<(ostream& out, const Matrix & m)
标签: c++ class reference operator-overloading