[C++-sig] Data members and inheritance
David Abrahams
dave at boost-consulting.com
Tue Nov 12 18:35:11 CET 2002
Kerim Borchaev <warkid at hotbox.ru> writes:
> Hello.
>
> I'm trying to export a class's data member that's declared in parent
> class. But I can't. Please explain me what am I doing wrong.
>
> Here's the test code:
>
> //hello.cpp
> #include <boost/python.hpp>
> using namespace boost::python;
>
> struct t {
> float a;
> };
>
> struct xt : t {
> };
>
> BOOST_PYTHON_MODULE(hello)
> {
> class_<xt>("xt", no_init)
> .def_readonly("a", &xt::a);
> }
You need to explicitly cast your member pointer to the right type:
.def_readonly("a", (float xt::*)&xt::a);
I've added a fix to the CVS which makes this unneccessary.
--
David Abrahams
dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution
More information about the Cplusplus-sig
mailing list