how can use a non-static class member function as the custom deleter of std::unique_ptr?
-
When I attempt to set custom deleter of std::unique_ptr, I got this error: .\src\iMoney.cpp(5): error C2664: 'std::unique_ptr<_Ty,_Dx>::unique_ptr(HINSTANCE__ *,void (__cdecl *const &)(HMODULE))' : cannot convert parameter 2 from 'void (__thiscall iMoney::* )(HMODULE)' to 'void (__cdecl *const &)(HMODULE)' 2> with 2> [ 2> _Ty=HMODULE, 2> _Dx=void (__cdecl *)(HMODULE) 2> ] 2> Reason: cannot convert from 'void (__thiscall iMoney::* )(HMODULE)' to 'void (__cdecl *const )(HMODULE)' 2> There is no context in which this conversion is possible 2> 2>Build FAILED. anybody can help me? Here is my code snippet:
//this is my non-static class member variable
std::unique_ptr m_ptrModule;void iMoney::freeLib(HMODULE hModule)//this is the non-static class member function
{
m_pThisApp->FreeLibrary(hModule);
}//this my constructor
iMoney::iMoney(CReader_App* pApp)
: m_pThisApp(pApp)
, m_ptrModule(nullptr, &iMoney::freeLib)
{
//hello money, i love you so much~
} -
When I attempt to set custom deleter of std::unique_ptr, I got this error: .\src\iMoney.cpp(5): error C2664: 'std::unique_ptr<_Ty,_Dx>::unique_ptr(HINSTANCE__ *,void (__cdecl *const &)(HMODULE))' : cannot convert parameter 2 from 'void (__thiscall iMoney::* )(HMODULE)' to 'void (__cdecl *const &)(HMODULE)' 2> with 2> [ 2> _Ty=HMODULE, 2> _Dx=void (__cdecl *)(HMODULE) 2> ] 2> Reason: cannot convert from 'void (__thiscall iMoney::* )(HMODULE)' to 'void (__cdecl *const )(HMODULE)' 2> There is no context in which this conversion is possible 2> 2>Build FAILED. anybody can help me? Here is my code snippet:
//this is my non-static class member variable
std::unique_ptr m_ptrModule;void iMoney::freeLib(HMODULE hModule)//this is the non-static class member function
{
m_pThisApp->FreeLibrary(hModule);
}//this my constructor
iMoney::iMoney(CReader_App* pApp)
: m_pThisApp(pApp)
, m_ptrModule(nullptr, &iMoney::freeLib)
{
//hello money, i love you so much~
}