新的C ++ 11范围为(foreach)语法:哪些编译器支持它? [英] New C++11 range-for (foreach) syntax: which compilers support it?

查看:252
本文介绍了新的C ++ 11范围为(foreach)语法:哪些编译器支持它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这篇由Jeremy Siek发表的BoostCon演示文稿中看到了这个c ++ 11代码片段:

I saw this c++11 code fragment in this BoostCon presentation by Jeremy Siek:

deque<int> topo_order;
topological_sort(g, front_inserter(topo_order));

for (int v : topo_order){ //line 39
    cout << tasks[v] << endl;
}

尝试在gcc中编译时会出现以下错误:

Upon trying to compile in gcc there is the following error:

main.cpp:39: error: expected initializer before ‘:’ token

推荐答案

那么我想知道哪些编译器实际上支持这种语法? p>至少GCC 支持4.6 (功能被称为基于范围的)。如果您已经有最新版本,不要忘记添加 -std = c ++ 0x 选项。

Well, at least GCC supports it in 4.6 (feature is called "Range-based for"). If you already have the latest version, don't forget to add the -std=c++0x option.

这篇关于新的C ++ 11范围为(foreach)语法:哪些编译器支持它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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