我有一個函數getTotal:捕獲打破我lambda函數
int getTotal(const HitMap& hitMap, bool(*accept)(int chan))
其中第二個參數是其中容器hitMap成員應該被添加到總的一個bool功能指定。
我試圖用lambda來調用它。這工作:
auto boxresult =
getTotal(piHits, [](int pmt)->bool
{ return (pmt/100) == 1;});
但這並不:
int sector = 100;
auto boxresult =
getTotal(piHits, [sector](int pmt)->bool
{ return (pmt/sector) == 1;});
我從我的編譯器(GCC 4.6.3)得到錯誤
cannot convert ‘main(int, char**)::<lambda(int)>’ to ‘bool (*)(int)’
for argument ‘2’ to ‘int getTotal(const HitMap&, bool (*)(int))’
。我試過[§or]
和[=sector]
,但沒有任何區別。
我在做什麼錯?
只有未捕獲的lambdas可以轉換爲函數*指針*。期。 – Xeo 2013-04-22 11:27:12