[C++-sig] Call Policy Question

Mike Thompson mike.spam.filter at day8.com.au
Thu Nov 4 08:17:45 CET 2004

I have a member function which returns an object and I'm trying to 
define a call policy for that member function which will:
    1.  cause the returned object to be managed:
        its a new object and needs to be managed.

    2.   register that the returned object holds a
         reference to the originating object (but not visa-versa)

but I can't work out how to combine the two.

I need 1. above because the returned object is new and needs to be managed.

I need 2. above because this returned object has references BACK
to the object who's member function supplies it.

So the returned object can be destroyed without the original being 
effected, but destruction of the original MUST wait until the returned 
object is gone.

Some code which hopes to capture this ...

class Orig;

class Fresh {
         Fresh(Orig* o) : o_(o) {}

         Orig* o_;

class Orig {
         Fresh* newFresh()  { return new Fresh(this); }


     class_<Orig>("Orig", no_init)
         .def("newFresh", &Orig::newFresh, XXXXX)

What should XXXXX be??

Help greatly appreciated.  I can't work this out from the tutorial and 
test harness code.


More information about the Cplusplus-sig mailing list