[C++-sig] Inherited instance variables
David Abrahams
dave at boost-consulting.com
Wed Mar 5 15:57:02 CET 2003
Matt Giger <mgiger at lunarsoft.com> writes:
> Hi, I just discovered Boost.Python and I am very impressed (as I am
> with most of Boost). I have embedded a Python interpreter in my
> project and would like to tie in some C++ classes but am having
> problems with inherited member variables.
Matt, are you using Boost 1.29.0 or the CVS? There have been some
improvements in handling of mutable attributes.
> Here is my example:
>
> C++
> ---
>
> struct foo {
> foo(void) {}
> virtual ~foo(void) {}
> virtual bool handle_evt(object event) { return false; }
> list children;
> }
>
> struct foowrap : foo {
> foowrap(PyObject* self) : self_(self) {}
> foowrap(PyObject* self, const foo& f) : foo(f), self_(self) {}
> bool handle_evt(object event)
> { return call_method<bool>(self_, "handle_evt", event); }
> static bool def_handle_evt(foo* f, object event)
> { return f->foo::handle_evt(event); }
> PyObject* const self_;
> };
>
> BOOST_PYTHON_MODULE(foomod)
> {
> class<foo, foowrap>("foo")
> .def("handle_evt", &foowrap::def_handle_evt)
> .def_readwrite("children", &widget::children);
> }
This won't compile; where's widget?
...
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list