Boost logo

Boost :

From: art (art_at_[hidden])
Date: 2005-12-10 09:06:50


I agree, the shared_ptr also lacks for that functionality.

-----Original Message-----
From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]]
On Behalf Of Stefan Popov
Sent: Friday, December 09, 2005 9:09 PM
To: boost_at_[hidden]
Subject: [boost] intrusive_ptr and overloading not working under VC++ 8

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.

Best,
Stefan

_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk