我正在尝试用intrusive_ptr
.
由于开罗的东西已经有了引用计数,我写了一个非常简单的包装:
#include <boost/intrusive_ptr.hpp>
inline void intrusive_ptr_add_ref(cairo_surface_t* self)
{
cairo_surface_reference(self);
}
inline void intrusive_ptr_release(cairo_surface_t* self)
{
cairo_surface_destroy(self);
}
inline void intrusive_ptr_add_ref(cairo_t* self)
{
cairo_reference(self);
}
inline void intruisve_ptr_release(cairo_t* self)
{
cairo_destroy(self);
}
namespace XXX
{
typedef boost::intrusive_ptr<cairo_surface_t> CairoSurfacePtr;
typedef boost::intrusive_ptr<cairo_t> CairoPtr;
}
但是,当我尝试创建 的实例时CairoPtr
,编译器似乎使用了该函数cairo_surface_t
而不是cairo_t
:
/usr/include/boost/smart_ptr/intrusive_ptr.hpp: In instantiation of 'boost::intrusive_ptr<T>::~intrusive_ptr() [with T = _cairo]':
../GenoEyeCandy/genoeyewidget.cpp:12:18: required from here
/usr/include/boost/smart_ptr/intrusive_ptr.hpp:97:49: error: cannot convert '_cairo*' to 'cairo_surface_t* {aka _cairo_surface*}' for argument '1' to 'void intrusive_ptr_release(cairo_surface_t*)'
if( px != 0 ) intrusive_ptr_release( px );
我只是不明白为什么编译器无法找到正确的函数。