此代码:

#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桌面版-mingw4.4(qt sdk)。我添加了以下标志:QMAKE_cxflags+=-std=c++0x

最佳答案

编译器不支持lambda表达式。

10-02 18:43