[C++-sig] [boost.python] char arrays in structs

Markus Schöpflin markus.schoepflin at comsoft.de
Tue Jul 5 10:11:23 CEST 2005


David Abrahams wrote:

> "Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com> writes:
> 
> 
>>>You mean thin wrapper as follows?
>>>
>>>struct wrap_foo : public foo
>>>{
>>>   char const *get_bar() { return bar; }
>>>};
>>>
>>>and then
>>>
>>>class_<foo_derived>("foo")
>>>   .def_property("bar", &foo_derived::get_bar)
>>>   ;
>>
>>You don't have to use inheritance just to provide a wrapper. 
> 
> In fact, it won't work in this case.  You can't call a wrap_foo member
> function on a foo object.

In fact I wanted to write:

struct wrap_foo : public foo
{
   char const *get_bar() const { return bar; }
};

...

   class_<wrap_foo>("foo")
     .add_property("bar", &wrap_foo::get_bar)
     ;

This works like a charm.

Thanks, Markus




More information about the Cplusplus-sig mailing list