我正在尝试将 operator+ 的结果返回给 operator= 但在 operator = 中返回 *this 时得到一个虚假值;调用 rhs 并访问其函数时,值是正确的,但 operator = 没有发送类的副本有什么问题?
VecXd& operator=(const VecXd &rhs)
{
cout << rhs.vecArr[0] << " " << rhs.vecArr[1] << " " << rhs.vecArr[2] << " " << endl;
return *this;
}
VecXd& operator+(const VecXd& rhs){
VecXd& result = *this;
cout << "TEST FOR DIMENSION-> " << dimension << endl;
if(result.dimension == rhs.dimension) //dimension level check
{
for(int i = 0; i < rhs.dimension; i++)
{
result.vecArr[i] += rhs.vecArr[i];
cout << result.vecArr[i] << " our new value" << endl;
}
cout << result << " result test!" << endl;
return result;
}
else{
cout << "Dimensions do not match!!! Error!" << endl;
}
}
帮助?谢谢你!