[C++-sig] call policies help needed

Neal Becker ndbecker2 at gmail.com
Thu May 25 15:03:12 CEST 2006


Roman Yakovenko wrote:

> On 5/25/06, Neal Becker <ndbecker2 at gmail.com> wrote:
>> Is there something wrong with this, which looks simpler to my (naive)
>> eyes?:
>>
>> struct A {};
>>
>> struct B {
>>   B (A& _a) : a (_a) {}
>>   A& a;
>> };
>>
>> static A& getA (B& b) {
>>   return b.a;
>> }
> 
[...]
>> BOOST_PYTHON_MODULE(demod4)
>> {
>>   class_<A> ("A");
>>   class_<B> ("B", init<A&>()
>>                         [with_custodian_and_ward<1,2>()])
>>     .def ("getA", &::getA, return_internal_reference<>())
> 
> Member variable "a" is not really internal reference. Class "B" does not
> manage it's life time.
> 

I'm confused.  I thought it worked like this:

In python, create an a=A().  Then create a b=B(a).  Using
custodian_and_ward, 'a' will not be deleted as long as 'b' is alive.  Then
c=getA() using return_internal_reference will ensure that 'b' is not
deleted as long as python holds 'c'.  Is this not correct?





More information about the Cplusplus-sig mailing list