简体   繁体   English

lambda表达式语法错误

[英]Error in lambda expression syntax

This code: 这段代码:

#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;
}

generates these errors: 生成这些错误:

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'

The project builds on Linux, but on Windows it does not. 该项目建立在Linux上,但在Windows上却没有。 My Qt version: Qt 4.7.4 for Desktop - MinGW 4.4 (Qt SDK). 我的Qt版本:桌面Qt 4.7.4 - MinGW 4.4(Qt SDK)。 I added following flag: QMAKE_CXXFLAGS += -std=c++0x 我添加了以下标志:QMAKE_CXXFLAGS + = -std = c ++ 0x

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM