提问者:小点点

C++,调用“filter”的o匹配函数


我编写了一个名为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)


共1个答案

匿名用户

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)

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(c++|调用|filter|o|匹配|函数)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?