<br><div><span class="gmail_quote">On 10/14/07, <b class="gmail_sendername">Simon Norberg</b> <<a href="mailto:simon@dackbrann.net">simon@dackbrann.net</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello,<br>im trying to get python to read and write to a struct inside a class<br>in the same way i do in c++<br>Customers hej;<br>hej.address.contact = "The Devil";<br><br>but i cant even get the code to compile, any suggestions?
<br><br>#include <iostream><br>#include <string><br><br>using namespace std;<br>class Customers {<br>private:<br>struct s_address<br>{<br>string contact;<br>string street1;<br>string street2;<br>string city;<br>
string province;<br>string postalCode;<br>string country;<br>};<br>public:<br>s_address address;<br>Customers(){}<br>~Customers(){}<br>};<br></blockquote></div><br>1. you cannot export variable, without exporting its type first: you have to expose s_address class too, if you want to expose address mem. variable.
<br><br>2. here is the code that was generated by Py++( <a href="http://language-binding.net/">http://language-binding.net/</a> ), the only change I did for original code was to change everything to public.<br><br>#include "boost/python.hpp"
<br><br>#include "1.hpp"<br><br>namespace bp = boost::python;<br><br>BOOST_PYTHON_MODULE(pyplusplus){<br> { //::Customers<br> typedef bp::class_< Customers > Customers_exposer_t;<br> Customers_exposer_t Customers_exposer = Customers_exposer_t( "Customers" );
<br> bp::scope Customers_scope( Customers_exposer );<br> bp::class_< Customers::s_address >( "s_address" ) <br> .def_readwrite( "city", &Customers::s_address::city )
<br> .def_readwrite( "contact", &Customers::s_address::contact ) <br> .def_readwrite( "country", &Customers::s_address::country ) <br> .def_readwrite( "postalCode", &Customers::s_address::postalCode )
<br> .def_readwrite( "province", &Customers::s_address::province ) <br> .def_readwrite( "street1", &Customers::s_address::street1 ) <br> .def_readwrite( "street2", &Customers::s_address::street2 );
<br> Customers_exposer.def( bp::init< >() );<br> Customers_exposer.def_readonly( "address", &Customers::address );<br> }<br>}<br><br clear="all"><br>-- <br>Roman Yakovenko<br>C++ Python language binding
<br><a href="http://www.language-binding.net/">http://www.language-binding.net/</a>