Boost logo

Boost :

From: art (art_at_[hidden])
Date: 2005-12-10 08:49:50


Does intrusive_ptr work with overloading on any other compiler?

This is a general problem and as I proposed above to solve the ambiguity you
have to use SFINE in template constructor of intrusive_ptr/shared pointer.

template< class T2 >
shared_ptr( const shared_ptr<T2>& s_ptr, typename
enable_if<is_convertible<T*,T2*>::result, void* >::type = 0)
{ ... }

I think it should be added to boost smartptr.

Artyom

"Stefan Popov" <stefan.popov_at_[hidden]> wrote in message
news:<6dbc126a0512091009y28a7c321if705f64ef22999f0_at_[hidden]>...
> 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