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

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Mon Jul 4 19:12:07 CEST 2005

--- Markus Schöpflin <markus.schoepflin at comsoft.de> wrote:
> > Here bar_t is equivalent to a plain char*. The size information is lost.
> This
> > due to the C heritage.
> Duh, I keep forgetting about that. But this makes me wondering why the 
> custom converter indeed does the trick in my example.

Sorry, David corrected me here. Apparently there is a difference between

  foo(char s[4])

and what you have. I wasn't aware of that.

> 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. An unbound
function  will also work if the first argument is foo& or foo const& (and maybe
even foo* etc., I am not sure):

char const*
get_bar(foo& self) { return foo.bar(); }


    .def("get_bar", get_bar)

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

More information about the Cplusplus-sig mailing list