我正在尝试将 OpenCV 的 C-API (CvPOSITObject) 中的对象包装在智能指针中。据我了解,它应该类似于以下内容:
unique_ptr<CvPOSITObject, decltype(cvReleasePOSITObject)> positObject;
positObject = unique_ptr<CvPOSITObject, decltype(cvReleasePOSITObject)>(cvCreatePOSITObject(param1, param2), cvReleasePOSITObject);
但我得到一个编译器错误,谷歌并没有真正帮助。
这两个函数的声明是:
CVAPI(CvPOSITObject*) cvCreatePOSITObject( CvPoint3D32f* points, int point_count );
CVAPI(void) cvReleasePOSITObject( CvPOSITObject** posit_object );
我得到类似的东西
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\memory(1227): error C2207: 'std::_Unique_ptr_base<_Ty,_Dx,_Empty_deleter>::_Mydel' : a member of a class template cannot acquire a function type
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\memory(1322): warning C4180: qualifier applied to function type has no meaning; ignored
1> Myfile.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\memory(1221): warning C4180: qualifier applied to function type has no meaning; ignored
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\memory(1283) : see reference to class template instantiation 'std::_Unique_ptr_base<_Ty,_Dx,_Empty_deleter>' being compiled
1> with
1> [
1> _Ty=CvPOSITObject,
1> _Dx=void (CvPOSITObject **),
1> _Empty_deleter=false
1> ]
1> C:\MyDir\Myfile.hpp(71) : see reference to class template instantiation 'std::unique_ptr<_Ty,_Dx>' being compiled
1> with
1> [
1> _Ty=CvPOSITObject,
1> _Dx=void (CvPOSITObject **)
1> ]
我该如何正确地做到这一点?