linux下g ++编译器中的lambda表达式 [英] lambda expression under g++ compiler in linux

查看:193
本文介绍了linux下g ++编译器中的lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用c ++ find_if()lambda表达式,在我编译的vc编译器中没有任何错误,并且我无法在linux中编译它:debian:g ++ 4.4:



-CPP函数:

  istream_iterator< string> it = find_if(istream_iterator< string>(ss),
f,
[=](const string& str)
{return str == to_string(urlHash);});

- 错误输出:

  -error:期望的主表达式在'['令牌之前
-error:预期的主表达式在'='令牌之前
-error:expected'primary'令牌
-error:在'const'之前预期的primary-expression

问题1 :这是一个与c ++版本相关的问题,尽管使用了-std = c ++ 0x标志,没有任何变化。

question 2 :尽管我在我的机器上安装了gcc 4.7,但我无法使用-std = c ++ 11标志。



谢谢;

解决方案


问题1 :这是与c ++版本相关的问题, -std = c ++ 0x标志,没有任何变化。


是的。 GCC 4.4不支持Lambdas。您将需要升级到或安装版本4.5或更高版本。有关更多详情,请参阅



< blockquote>

问题2 :我无法使用-std = c ++ 11标志,尽管我在机器中安装了gcc 4.7。 $ b

这不是问题。


i need to to use c++ find_if() lambda expression, in my vc compiler it compiles without any errors, and i can't compile it in linux:debian:g++4.4 :

-CPP function:

    istream_iterator<string> it = find_if(istream_iterator<string>(ss),
        f,
        [=](const string& str)
        {return str == to_string(urlHash);});

-Error output:

    -error: expected primary-expression before '[' token
    -error: expected primary-expression before '=' token
    -error: expected primary-expression before ']' token
    -error: expected primary-expression before 'const'

question 1 : is this a version related problem of c++, despite using the -std=c++0x flag, nothing changes.

question 2 : i can't use -std=c++11 flag, despite that i installed the gcc 4.7 in my machine.

thanks;

解决方案

question 1 : is this a version related problem of c++, despite using the -std=c++0x flag, nothing changes.

Yes. Lambdas are not supported in GCC 4.4. You will need to upgrade to or install version 4.5 or higher. See here for more details.

question 2 : i can't use -std=c++11 flag, despite that i installed the gcc 4.7 in my machine.

That is not a question.

这篇关于linux下g ++编译器中的lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆