[C++-sig] shared_ptr converters

Nicodemus nicodemus at globalite.com.br
Mon Apr 21 20:46:08 CEST 2003


David Abrahams wrote:

>Nicodemus <nicodemus at globalite.com.br> writes:
>
>  
>
>>David Abrahams wrote:
>>
>>    
>>
>>>Nicodemus <nicodemus at globalite.com.br> writes:
>>> However, there is one significant difference: if you don't specify
>>>shared_ptr<Y> then you will not be able to pass a Python X object as a
>>>shared_ptr<Y>& argument.  Among other things that means you will not
>>>be able to expose member functions of the shared_ptr as methods of the
>>>wrapped X (see Raoul Gough's recent postings about proxies).  You will
>>>still be able to pass a Python X object as shared_ptr<X>,
>>>shared_ptr<Y>, shared_ptr<X> const&, or shared_ptr<Y> const&.
>>>
>>>      
>>>
>>You mean that a function that receives a shared_ptr<X>& wouldn't work?
>>Because the following does:
>>
>>int Test(boost::shared_ptr<A>& a)
>>{
>>    return a->f();
>>}          >>> from test import *
>> >>> a = New()
>> >>> Test(a)
>>1
>>
>>Or am I misunderstood your response? 
>>    
>>
>
>Yes, my response was badly-phrased.  I should've said: if you don't
>specify shared_ptr<X>, you won't be able to pass an X object
>_constructed from Python_ to a function expecting shared_ptr<X>&:
>
>             >>> a = A()
>             >>> Test(a)
>             Traceback...
>  
>

I see... then that solution doesn't solve this more common case (at
least more common than trying to use shared_ptr's with virtual wrappers,
as in my original post). I believe that reverting Pyste back to specify
the shared_ptr as holder for class_ is the better thing to do for now.
What do you think Dave? Thanks for helping!

Regards,
Nicodemus.







More information about the Cplusplus-sig mailing list