What wrapper class in C++ should I use for automated resource management?

前端 未结 8 1055
余生分开走
余生分开走 2020-12-16 13:56

I\'m a C++ amateur. I\'m writing some Win32 API code and there are handles and weirdly compositely allocated objects aplenty. So I was wondering - is there some wrapper clas

8条回答
  •  有刺的猬
    2020-12-16 14:28

    I don't think there is anything in the standard library, and I also doubt that shared pointers (as in boost) can be used (since those would expect pointer to HANDLE, not HANDLE).

    It shouldn't be hard to write one yourself, following the scope guard idiom (and making use of templates/function pointers etc if you so choose).

提交回复
热议问题