2014-01-06 58 views
1

我有涉及,編譯罰款拉姆達一小段程式碼,但智能感知拋出一個錯誤。VS Express 2012 C++ lambda Intellisense錯誤?

items.erase(remove_if(begin(items), end(items), 
[](const Item& mItem){ return mItem.booleanMember; }), 
end(items)); 

的錯誤是

IntelliSense: more than one conversion function from "lambda []bool (const Item &mItem)->bool" to "<error-type>" applies: 
     function "lambda []bool (const Item &mItem)->bool::operator bool (*)(const Item &mItem)() const" 
     function "lambda []bool (const Item &mItem)->bool::operator bool (*)(const Item &mItem)() const" 
     function "lambda []bool (const Item &mItem)->bool::operator bool (*)(const Item &mItem)() const" 

如果我更改代碼以

items.erase(remove_if(begin(items), end(items), 
[&](const Item& mItem)->bool{ return mItem.booleanMember; }), 
end(items)); 

然後錯誤消失。我會很好,但我不完全知道發生了什麼。我知道我沒有明確指定一個布爾返回值(以及與此改變的代碼,我),但我覺得我沒必要,如果有在lambda只有一行。另外,我不知道是什麼[&]在做什麼。

+0

不,你不需要在這種情況下,顯式的返回類型。並且[&]是捕獲條款,在許多lambda介紹中進行了解釋。 – chris

回答

2

這是一個智能感知的錯誤;它已在Visual Studio 2013中修復。您可以忽略錯誤的錯誤。