Why STL containers are preferred over MFC containers?

后端 未结 13 1625
时光说笑
时光说笑 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:47

    MFC containers derive from CObject and CObject has the assignment operator made private. I have found this very annoying in practice.

    std::vector, unlinke CArray, guarantees that the memory block is contiguous, thus you can interop with C programming interfaces easily:

    std::vector buffer; 
    char* c_buffer = &*buffer.begin();
    

提交回复
热议问题