C++运算符重载实现连加

这是函数原型,成员函数:Matrix operator+(const Matrix&)
这是函数体
Matrix Matrix::operator+(const Matrix& m)
{
Matrix temp;
for (int i = 0;i < 2;i++)
{
for (int j = 0;j < 2;j++)
{
temp.p[i][j] = p[i][j] + m.p[i][j];
}
}
return temp;
}
运行时出现错误,无法实现连加,可是没有报错或警告的消息,这是怎么回事?
调试时出现这个:
[下面的框架可能不正确和/或缺失,没有为 ucrtbased.dll 加载符号]

要实现连加需要将操作符形参申明为const引用类型。如下
//操作符申明为友元并重载
friend matrix operator+(const matrix &M, const matrix &N) {
if (M.num==N.num)
{
matrix temp = M;
for (std::size_t i = 0; i != M.num.first; i++)
for (std::size_t j = 0; j != M.num.second; j++)
temp.data[i][j] += N.data[i][j];
return temp;
}
else
throw std::range_error("Matrix do not match !");
}

似乎是工程或者IDE的问题,新建一个工程写这些代码试试

一般要实现连续使用某个操作符都需要返回相应的引用类型。

应该是系统的问题 你看看你的系统里有这个usrtbased.dll文件没 从网上下一个装上再运行试试看呢