我写了一个名为Matrix
的类,下面的代码有效
Matrix Matrix::operator<(int num) const {
Matrix tmp=*this;
Between t(1,2);
return filter(*this,t);
}
但是为什么它不能编译?
Matrix Matrix::operator<(int num) const {
Matrix tmp=*this;
return filter(*this,Between(1,2););
}
以及如何解决此问题?
Matrix filter (const Matrix& int_matrix, Between& field)
[filter
通过左值引用第二个参数来引用非常量,该常量不能绑定到像Between(1,2)
这样的临时对象。
作为解决方法,您可以使filter
通过左值引用对const进行参数传递,这可以绑定到临时对象。
Matrix filter (const Matrix& int_matrix, const Between& field)
或传递值。
Matrix filter (const Matrix& int_matrix, Between field)