[C++-sig] with_custodian_and_ward problem

Hans Meine hans_meine at gmx.net
Sat Jun 9 21:13:45 CEST 2007


Hi Roman,

thanks for looking at my problem.

On Samstag 09 Juni 2007, Roman Yakovenko wrote:
> > I created a testcase (attached, too):
> >
> > This is my class which internally stores a reference to an object given
> > to the
> >
> > constructor:
> > > struct T
> > > {
> > >     T(int &foo) : foo_(foo) {}
> > >     int &foo_;
> > > };
>
> The constructor takes immutable type( int ) by reference. You cannot
> directly expose this constructor.

Argh.  OK.  That's an artifact caused be /me trying to strip everything down 
as much as possible (in the original, complext classes and rvalue converters 
were involved).  Just imagine I had used my own class.

> > > int someInt;
> > >
> > > static T *createT()
> > > {
> > >     return new T(someInt);
> > > }
> >
> > [...]
> > >     class_<T, boost::noncopyable>("T", no_init)
> > >         .def("__init__", make_constructor(
> > >                  &createT,
> > >                  with_custodian_and_ward_postcall<0, 1>()));
> >
> > How can I properly tell BPL to make sure that the object passed to the
> > constructor must not be deleted before the "T" instance?
>
> In the example you gave you didn't pass any argument to "createT" function.

Oh, right.  Again, I messed up the testcase.  I hope I did better this time, 
see attachment.

Ciao, /  /                                                    .o.
     /--/                                                     ..o
    /  / ANS                                                  ooo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: caw_testcase2.cxx
Type: text/x-c++src
Size: 602 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070609/42250f75/attachment.cxx>


More information about the Cplusplus-sig mailing list