lambda表达式语法错误

时间:2012-01-02 11:41:47

标签: c++ algorithm lambda

此代码:

#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

1 个答案:

答案 0 :(得分:2)

您的编译器不支持lambda表达式。