Making a HANDLE RAII-compliant using shared_ptr with a custom deleter

前端 未结 4 961
广开言路
广开言路 2021-01-02 04:35

I\'ve recently posted a general question about RAII at SO. However, I still have some implementation issues with my HANDLE example.

A HANDLE is typedeff

4条回答
  •  攒了一身酷
    2021-01-02 05:04

    Don't bother with shared_ptr for that, use ATL::CHandle.

    Here is why:

    • When you see CHandle you know that it's a RAII wrapper for a handle.
    • When you see shared_ptr you don't know what it is.
    • CHandle doesn't make an ownership shared (however in some cases you may want a shared ownership).
    • CHandle is a standard for a windows development stack.
    • CHandle is more compact than shared_ptr with custom deleter (less typing/reading).

提交回复
热议问题