为什么STL容器比MFC容器更受青睐? [英] Why STL containers are preferred over MFC containers?

查看:110
本文介绍了为什么STL容器比MFC容器更受青睐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,我曾经使用MFC集合类,例如CArrayCMap.一段时间后,我切换到STL容器并使用了一段时间.尽管我发现STL更好,但我无法指出确切的原因.一些推理,例如:

Previously, I used to use MFC collection classes such CArray and CMap. After a while I switched to STL containers and have been using them for a while. Although I find STL much better, I am unable to pin point the exact reasons for it. Some of the reasoning such as :

  1. 它需要MFC:不存在,因为我程序的其他部分都使用MFC
  2. 这取决于平台:不成立,因为我仅在Windows上运行我的应用程序.(无需可移植性)
  3. 它在C ++标准中定义:可以,但是MFC容器仍然可以工作

我能提出的唯一理由是我可以在容器上使用算法.还有什么其他我想念的原因-是什么使STL容器比MFC容器更好?

The only reason I could come up is that I can use algorithms on the containers. Is there any other reason that I am missing here - what makes STL containers better than MFC containers?

推荐答案

Ronald Laeremans,VC ++产品部门经理,甚至是

Ronald Laeremans, VC++ Product Unit Manager, even said to use STL in June 2006:

坦率地说,团队会给您相同的答案. MFC集合类仅用于向后兼容. C ++有一个用于收集类的标准,即Standards C ++ Library.在MFC应用程序中使用任何标准库都没有技术上的缺点.

And frankly the team will give you the same answer. The MFC collection classes are only there for backwards compatibility. C++ has a standard for collection classes and that is the Standards C++ Library. There is no technical drawback for using any of the standard library in an MFC application.

我们不打算在此领域进行重大更改.

We do not plan on making significant changes in this area.

Ronald Laeremans
代理产品部门经理
Visual C ++团队

Ronald Laeremans
Acting Product Unit Manager
Visual C++ Team

但是,在我处理Windows安装阶段运行的某些代码的那一刻,我被禁止使用STL容器,但被告知要使用ATL容器(实际上尤其是CString,我想这实际上不是一个容器).原因是STL容器依赖于运行时位,而这些运行时位在必须执行代码时可能实际上并不可用,而那些问题对于ATL集合并不存在.这是一个非常特殊的情况,不应影响99%的代码.

However, at one point where I was working on some code that ran during the installation phase of Windows, I was not permitted to use STL containers, but was told to use ATL containers instead (actually CString in particular, which I guess isn't really a container). The explanation was that the STL containers had dependecies on runtime bits that might not actually be available at the time the code had to execute, while those problems didn't exist for the ATL collections. This is a rather special scenario that shouldn't affect 99% of the code out there.

这篇关于为什么STL容器比MFC容器更受青睐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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