繁体   English   中英

lambda表达式语法错误

[英]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.

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