我编写了一个名为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););
}
怎么解决这个问题?
矩阵筛选器(常量矩阵和int_matrix,Between&;field)
filter
通过lvalue-referenceofnon-const获取第二个参数,该参数不能绑定到(1,2)之间的临时对象(如between(1,2)
)。
作为解决办法,您可以使filter
通过lvalue-reference获取参数到const,它可以绑定到临时对象。
Matrix filter (const Matrix& int_matrix, const Between& field)
或按值传递。
Matrix filter (const Matrix& int_matrix, Between field)