c++boostboost-smart-ptr

failed to used correct function for boost intrusive_ptr


I'm trying to wrap Cairo with intrusive_ptr.

As the things in Cairo already have reference counting, I wrote a very simple wrap:

#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;
}

However, when I try to create an instance of CairoPtr, it seems that the compiler used the function for cairo_surface_t instead of 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 );

I just can't understand why the compiler failed to locate the correct function.


Solution

  • It's because I mis-spelled the intruisve_ptr_release. As a result, there's only one function named intrusive_ptr_release, which has argument type cairo_surface_t*.

    Damn it...