c++ - 为什么 STL 容器优于 MFC 容器?

标签 c++ mfc stl containers

以前,我使用过CArrayCMap 等MFC 集合类。一段时间后,我切换到 STL 容器并使用了一段时间。虽然我发现 STL 好多了,但我无法指出它的确切原因。一些推理如:

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

我能想到的唯一原因是我可以在容器上使用算法。还有什么我在这里遗漏的其他原因 - 是什么让 STL 容器比 MFC 容器更好

最佳答案

Ronald Laeremans,VC++ 产品部门经理,甚至 said to use STL 2006 年 6 月:

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
Acting Product Unit Manager
Visual C++ Team

但是,有一次我在编写一些在 Windows 安装阶段运行的代码时,不允许我使用 STL 容器,而是被告知要使用 ATL 容器(实际上是 CString 特别是,我猜这不是一个真正的容器)。解释是 STL 容器依赖于运行时位,这些位在代码必须执行时可能实际上不可用,而 ATL 集合不存在这些问题。这是一个相当特殊的场景,不应该影响 99% 的代码。

关于c++ - 为什么 STL 容器优于 MFC 容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1348078/

相关文章:

将 vector 数据写入文件的C++问题

c++ - 这个函数的顶部发生了什么

c++ - MFC 无法生成动态 DLL 文件

c++ - 使用 std::map 作为关联数组

c++ - 替换字符,如 replaceAll(string, start, end, '_' , '-' )

c++ - 在构造函数中创建一个指针以指向 C++ 中类的实例

c++ - 为 char* 动态分配内存时出错

c++ - MFC VC++:CMFCButton::SetFaceColor 不更改背景(脸部)颜色

c++ - 如何获得 std::map 的 std::set 键

c++ - 处理多个文件时,我必须在 COleDropTarget::OnDrop() 中返回哪个值?