Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-12-09 19:24:40


Stefan Popov wrote:

> 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.

This program:

#include <boost/intrusive_ptr.hpp>

class RefCnt
{
};

void intrusive_ptr_add_ref( RefCnt * );
void intrusive_ptr_release( RefCnt * );

class GLTexture: public RefCnt
{
};

class GLRenderBuffer: public RefCnt
{
};

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

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

int main()
{
    attachTarget( new GLTexture );
}

compiles for me under MSVC 8.


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