<br><div><span class="gmail_quote">On 10/14/07, <b class="gmail_sendername">Simon Norberg</b> &lt;<a href="mailto:simon@dackbrann.net">simon@dackbrann.net</a>&gt; 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 = &quot;The Devil&quot;;<br><br>but i cant even get the code to compile, any suggestions?
<br><br>#include &lt;iostream&gt;<br>#include &lt;string&gt;<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 &quot;boost/python.hpp&quot;
<br><br>#include &quot;1.hpp&quot;<br><br>namespace bp = boost::python;<br><br>BOOST_PYTHON_MODULE(pyplusplus){<br>&nbsp;&nbsp;&nbsp; { //::Customers<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typedef bp::class_&lt; Customers &gt; Customers_exposer_t;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Customers_exposer_t Customers_exposer = Customers_exposer_t( &quot;Customers&quot; );
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bp::scope Customers_scope( Customers_exposer );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bp::class_&lt; Customers::s_address &gt;( &quot;s_address&quot; )&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .def_readwrite( &quot;city&quot;, &amp;Customers::s_address::city )&nbsp;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .def_readwrite( &quot;contact&quot;, &amp;Customers::s_address::contact )&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .def_readwrite( &quot;country&quot;, &amp;Customers::s_address::country )&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .def_readwrite( &quot;postalCode&quot;, &amp;Customers::s_address::postalCode )&nbsp;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .def_readwrite( &quot;province&quot;, &amp;Customers::s_address::province )&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .def_readwrite( &quot;street1&quot;, &amp;Customers::s_address::street1 )&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .def_readwrite( &quot;street2&quot;, &amp;Customers::s_address::street2 );
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Customers_exposer.def( bp::init&lt; &gt;() );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Customers_exposer.def_readonly( &quot;address&quot;, &amp;Customers::address );<br>&nbsp;&nbsp;&nbsp; }<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>