Visual c++ quot;for eachquot; portability(Visual c++“为每个可移植性)
问题描述
我最近才发现 Visual C++ 2008(也许还有更早的版本?)支持 stl 列表等上的 for each 语法以促进迭代.例如:
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 循环.
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.
量子皮特
这似乎是 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++“为每个"可移植性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Visual c++“为每个"可移植性
基础教程推荐
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- c++ STL设置差异 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
