std::unique_ptr, deleters and the Win32 API
问题 In VC2012, I want to create a mutex in a constructor using a unique pointer and a deleter, so that I don't need to create a destructor just to call CloseHandle. I would have thought that this would work: struct foo { std::unique_ptr<HANDLE, BOOL(*)(HANDLE)> m_mutex; foo() : m_mutex(CreateMutex(NULL, FALSE, NULL), CloseHandle) {} } but on compiling I get an error: error C2664: 'std::unique_ptr<_Ty,_Dx>::unique_ptr(void *,int (__cdecl *const &)(HANDLE)) throw()' : cannot convert parameter 1