[英]Error in lambda expression syntax
這段代碼:
#include "Backpack.h"
#include <sstream>
#include <algorithm>
int Backpack::getCurrentWeight()
{
int weight = 0;
std::for_each(items.begin(),items.end(),[&](std::shared_ptr<PickupItem> item){ //8
weight +=item->getWeight();
});
return weight;
}
生成這些錯誤:
Backpack.cpp: In member function 'int Backpack::getCurrentWeight()':
Backpack.cpp:8: error: expected primary-expression before '[' token
Backpack.cpp:8: error: expected primary-expression before ']' token
Backpack.cpp:8: error: expected primary-expression before 'item'
該項目建立在Linux上,但在Windows上卻沒有。 我的Qt版本:桌面Qt 4.7.4 - MinGW 4.4(Qt SDK)。 我添加了以下標志:QMAKE_CXXFLAGS + = -std = c ++ 0x
您的編譯器不支持lambda表達式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.