2013-03-22 125 views
2

确定,代码为:lambda表达式错误:表达式必须修改的左值

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 
      } 
     } 
}); 

而且我已经写另一个类似的代码块,工作就好了。所以,这里有一点帮助。 PS:parallel_for来自Interl TBB。

+0

我阅读了lambda表达式语法,并将[=]更改为[&],现在它是完美的。 – 2013-03-22 09:13:55

回答

3

[=]导致lambda按值捕获,这意味着它会复制imageFiltered,并将副本标记为“const”。将[=]更改为[&]以捕获通过引用过滤的imageFiltered,这应能消除此问题。

相关问题