Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied! <p>Can't comment @jkp but his hint did the trick for me. My minimalistic case:</p> <p><em>RenderWorld.h</em></p> <pre class="lang-cpp prettyprint-override"><code>class RenderWorld { public: ... void addEntity(RenderEntity* entity) {entities.push_back(entity);}; std::vector&lt;RenderEntity*&gt; getEntities(void) {return entities;}; private: std::vector&lt;RenderEntity*&gt; entities; }; </code></pre> <p><em>RenderEntity.h</em></p> <pre class="lang-cpp prettyprint-override"><code> class RenderEntity { public: int getID(void) {return 42;}; }; </code></pre> <p><em>python-exportage.py.h</em> (compiles to exported.pyd)</p> <pre class="lang-cpp prettyprint-override"><code>BOOST_PYTHON_MODULE(exported) { class_&lt;RenderWorld&gt;("RenderWorld") .def("addEntity", &amp;RenderWorld::addEntity) .def("getEntities", &amp;RenderWorld::getEntities) ; class_&lt;RenderEntity, RenderEntity*&gt;("RenderEntity") .def("getID", &amp;RenderEntity::getID) ; class_&lt;std::vector&lt;RenderEntity*&gt; &gt;("PyVec") .def(boost::python::vector_indexing_suite&lt;std::vector&lt;RenderEntity*&gt; &gt;()) ; } </code></pre> <p>my python session:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; import exported &gt;&gt;&gt; world = exported.RenderWorld() &gt;&gt;&gt; world &lt;exported.RenderWorld object at 0x00000000024A0E58&gt; &gt;&gt;&gt; e1 = exported.RenderEntity() &gt;&gt;&gt; e1 &lt;exported.RenderEntity object at 0x000000000284DF48&gt; &gt;&gt;&gt; e1.getID() 42 &gt;&gt;&gt; world.addEntity(e1) &gt;&gt;&gt; world.getEntities() &lt;exported.PyVec object at 0x000000000234B1B0&gt; &gt;&gt;&gt; world.getEntities()[0] &lt;exported.RenderEntity object at 0x0000000002441F50&gt; &gt;&gt;&gt; world.getEntities()[0].getID() 42 &gt;&gt;&gt; e1 == world.getEntities()[0] False </code></pre> <p>Notable: The <code>RenderEntity*</code> will be wrapped in an other object. Look at these addresses and the last check. It's logical in a c++ perspective, but not in the python domain.</p> <p><a href="/questions/tagged/c%2b%2b" class="post-tag" title="show questions tagged 'c++'" rel="tag">c++</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload