问题描述
以前,我曾经使用MFC集合类,例如CArray
和CMap
.一段时间后,我切换到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 :
- 它需要MFC:不存在,因为我程序的其他部分都使用MFC
- 这取决于平台:不成立,因为我仅在Windows上运行我的应用程序.(无需可移植性)
- 它在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:
我们不打算在此领域进行重大更改.
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容器更受青睐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!