为什么 STL 容器优于 MFC 容器? [英] Why STL containers are preferred over MFC containers?

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

问题描述

以前,我使用过CArrayCMap 等MFC 集合类.一段时间后,我切换到 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++ 产品部门经理,甚至 2006年6月说用STL:

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

坦率地说,团队会给你同样的答案.MFC 集合类仅用于向后兼容.C++ 有一个集合类的标准,那就是标准 C++ 库.在 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天全站免登陆