std::unique_ptr with custom deleter for win32 LocalFree

后端 未结 4 950
离开以前
离开以前 2021-02-12 23:24

I have the win32 API CommandLineToArgvW which returns a LPWSTR* and warns me that

CommandLineToArgvW allocates a

4条回答
  •  一向
    一向 (楼主)
    2021-02-12 23:55

    I find shared_ptr a bit more useful as a generic resource guard. It does not require the deleter to be the part of template arguments and as such can be easily passed around.

    std::shared_ptr p(
        ::CommandLineToArgvW(L"cmd.exe p1 p2 p3", &n),
        ::LocalFree);
    

提交回复
热议问题