Boost logo

Boost :

From: Stefan Popov (stefan.popov_at_[hidden])
Date: 2005-12-10 12:19:41


Sorry,
I posted the wrong code. Here is the code causing the ambiguouty:

class RefCnt {};

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

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

typedef intrusive_ptr<GLTexture> GLTexturePtr;
typedef intrusive_ptr<GLOffscreenTexture> GLOffscreenTexturePtr;
typedef intrusive_ptr<GLRenderBuffer> GLRenderBufferPtr;

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

int main()
{
        GLOffscreenTexturePtr ptr = new GLOffscreenTexture;
        attachTarget(ptr);
}

Produces:
...\tst.cpp(...) : error C2668: 'attachTarget' : ambiguous call to
overloaded function

Peter Dimov wrote:
> 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.
>
> _______________________________________________
> 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