Visual c ++“用于每个”可移植性 [英] Visual c++ "for each" portability

查看:141
本文介绍了Visual c ++“用于每个”可移植性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是刚刚发现Visual c + + 2008(也许更早的版本以及?)支持每个语法stl列表等,以方便迭代。
例如:

I only just recently discovered that Visual C++ 2008 (and perhaps earlier versions as well?) supports for each syntax on stl lists et al to facilitate iteration. For example:

list<Object> myList;

for each (Object o in myList)
{
  o.foo();
}



我非常高兴地发现它,但我担心可移植性可怕的一天,当有人决定我需要能够编译我的代码说,GCC或一些其他编译器。

I was very happy to discover it, but I'm concerned about portability for the dreaded day when someone decides I need to be able to compile my code in say, gcc or some other compiler. Is this syntax widely supported and can I use it without worrying about portability issues?

推荐答案

因为每个都不是标准的C或C ++语法。如果你想在gcc或g ++中编译这个代码,你需要创建一个迭代器,并使用标准的循环。

For each is not standard C or C++ syntax. If you want to be able to compile this code in gcc or g++, you will need to create an iterator and use a standard for loop.

QuantumPete

QuantumPete


这似乎是MS Visual C ++中引入的一个新功能,因此这绝对不是便携式的。参考文献: http://msdn.microsoft.com/en-us/library/ xey702bw%28VS.80%29.aspx [/ edit]

[edit] This seems to be a new feature introduced into MS Visual C++, so this is definitely not portable. Ref: http://msdn.microsoft.com/en-us/library/xey702bw%28VS.80%29.aspx [/edit]

这篇关于Visual c ++“用于每个”可移植性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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