Why STL containers are preferred over MFC containers?

后端 未结 13 1613
时光说笑
时光说笑 2021-01-30 22:24

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.

13条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 22:39

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

    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

    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.

提交回复
热议问题