std::unique_ptr with custom deleter for win32 LocalFree

后端 未结 4 964
离开以前
离开以前 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-13 00:15

    Declaring of custom deleter is not so pretty, use of decltype() is faster. std::shared_ptr is an alternative, but it is larger than std::unique_ptr. If you don't want to share a pointer, then take a unique_ptr.

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

提交回复
热议问题