[C++-sig] Re: Call policy with constructor

David Abrahams dave at boost-consulting.com
Mon Oct 27 19:58:14 CET 2003


"Mike Rovner" <mike at nospam.com> writes:

> Pierre Barbier de Reuille wrote:
>> I want to define a constructor that takes a pointer a keep a reference
>> on it. So I need a call policy like 'with_custodian_and_ward<1,2>()'.
>>
>> But it fails at compile time. Here's me Boost.Python code :
>>
>> class_<RCPtr<Class> >(name, doc, init<optional<Class*> >())
>>       .def(init<RCPtr<Class> >())
>>       .def( init<Class*>(), with_custodian_and_ward<1,2>() )
>>       ;
>
> You have to use different syntax:
>
>       .def( init<Class*>()[with_custodian_and_ward<1,2>()] )
>
> See reference at www.boost.org/libs/python/doc/v2/init.html#init-spec

...and you probably don't want the optional<Class*> in the first
init<...>.


-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list