Boost logo

Boost :

From: Stefan Popov (stefan.popov_at_[hidden])
Date: 2005-12-09 13:09:22

I ran onto a problem when using intrusive_ptr, overloading and MS
visual studio 8

All my classes derive a reference counted class RefCnt. For example:

class GLTexture : public RefCnt {...};
class GLRenderBuffer : public RefCnt {...};

I define smart pointers using the intrusive_ptr class:

typedef boost::intrusive_ptr<GLTexture> GLTexturePtr;
typedef boost::intrusive_ptr<GLRenderBuffer> GLRenderBufferPtr;

Than I define a function accepting both GLTexturePtr and GLRenderBufferPtr :

void attachTarget(GLTexturePtr aTexture);
void attachTarget(GLRenderBufferPtr aBuffer);

invoking <code>attach(new GLTexture)</code> leads to an error:
ambiguous function call.

The reason is in the contructor of intrusive_ptr:
    template<class U> intrusive_ptr(intrusive_ptr<U> const & rhs) ...
which allows an invocation with an unrelated pointer.

Changing the constructor to
        template<class U> intrusive_ptr(
                intrusive_ptr<U> const & rhs,
                typename enable_if<boost::is_convertible<typename
boost::add_const<U*>::type, typename boost::add_const<T*>::type >
>::type* dummy = NULL

resolves the problem.

I think this is a bug.


Boost list run by bdawes at, gregod at, cpdaniel at, john at