[C++-sig] Re: def() vs. add_property()

Stefan Seefeld seefeld at sympatico.ca
Wed Jul 16 21:25:37 CEST 2003


David Abrahams wrote:
> Stefan Seefeld <stefan.seefeld at orthosoft.ca> writes:
> 
> 
>>hi there,
>>
>>I'v got a class that holds a reference to an external
>>object, which is accessible through a simple method:
>>
>>class Origin {};
>>
>>class Event
>>{
>>public:
>>   Event(const Origin *o) : my_origin(o) {}
>>   const Origin *GetOrigin() { return my_origin;}
>>private:
>>   const Origin *my_origin;
>>};
>>
>>I can expose the 'Event' and 'Origin' classes, as well
>>as &Event::GetOrigin, to python.
>>However, I'd rather like to make the origin accessible
>>as a (read-only) property. The problem is that the
>>'add_property' method doesn't take a return value policy,
>>so I have no way of telling python how to wrap the pointer.
>>
>>What is the suggested way to do that ?
> 
> 
> See make_getter/make_setter.  You can pass their results to
> add_property.
> 

make_getter seems to expect a pointer-to-member, while I
want a pointer-to-member-function. Am I missing something ?

Stefan





More information about the Cplusplus-sig mailing list