lambda expression error: expression must be a modifiable lvalue
Asked Answered
K

1

5

Ok, the codes are:

vector<vector<double>> imageFiltered;

// some processing codes here

parallel_for( blocked_range<unsigned>(0, imageFiltered.size()),
    [=](const blocked_range<unsigned>& r) {
        for( unsigned i = r.begin(); i != r.end(); ++i ){
            for( unsigned j = 0; j != imageFiltered[i].size(); ++j ) {
                imageFiltered[i][j] = 0; // error here:expression must be a modifiable lvalue
            }
        }
});

And I've write another similar code block which works just fine. So, a little help here. PS: parallel_for is from Interl TBB.

Kumamoto answered 22/3, 2013 at 8:43 Comment(1)
I read the lambda expression syntax, and change the [=] to [&], now it's perfect.Kumamoto
A
7

The [=] causes the lambda to capture by value, which means that it makes a copy of imageFiltered, and the copy is marked "const". Change the [=] to [&] to capture imageFiltered by reference, which should eliminate the problem.

Acervate answered 25/3, 2013 at 14:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.