[C++-sig] with_custodian_and_ward problem

Hans Meine meine at informatik.uni-hamburg.de
Fri Jun 8 13:48:35 CEST 2007


Hi!

I have a typical call policies problem, which I believed to be solvable with 
with_custodian_and_ward, but I cannot get it to compile.  (I am using 
make_constructor, maybe that is relevant?)  I guess that I simply did not 
understand BPL's reference counting policies correctly..

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_;
> };
>
> int someInt;
>
> static T *createT()
> {
>     return new T(someInt);
> }

I tried using this export code (and some others), which is obviously wrong:
>     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?

Ciao, /  /
     /--/
    /  / ANS

PS: I am currently using 1.34.0beta, does that matter?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: caw_testcase2.cxx
Type: text/x-c++src
Size: 491 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070608/8577ee9e/attachment.cxx>


More information about the Cplusplus-sig mailing list