user13659234
user13659234

Reputation:

C++, no matching function for call to 'filter'

I wrote a class called Matrix, with the following code which works

Matrix Matrix::operator<(int num) const {
    Matrix tmp=*this;
    Between t(1,2);
    return filter(*this,t);
}

but why this doesn't compile?

Matrix Matrix::operator<(int num) const {
    Matrix tmp=*this;
    return filter(*this,Between(1,2););
}

and how to fix this?

Matrix filter (const Matrix& int_matrix, Between& field)

Upvotes: 1

Views: 188

Answers (1)

songyuanyao
songyuanyao

Reputation: 172924

filter takes the 2nd parameter by lvalue-reference to non-const, which can't bind to temporaries like Between(1,2).

As the workaround you can make filter taking parameter by lvalue-reference to const, which could bind to temporary objects.

Matrix filter (const Matrix& int_matrix, const Between& field)

Or pass-by-value.

Matrix filter (const Matrix& int_matrix, Between field)

Upvotes: 1

Related Questions