Now we are into the dizzying world of template error messages :)<div><br class="webkit-block-placeholder"></div><div>So I have a class Matrix, which exposes a pointer to float, and a conversion operator to POINTER(c_float):</div>
<div><br class="webkit-block-placeholder"></div><div>struct Matrix {</div><div>int test();</div><div>float *ptr();</div><div>};</div><div><br class="webkit-block-placeholder"></div><div><div>struct ctypes_float_ptr</div><div>
{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>static PyObject *convert(float *ptr)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>object ctypes = import("ctypes");</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span> long_ addr((unsigned)ptr);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> object pointerType(ctypes["POINTER"](ctypes["c_float"]));</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span> return ctypes["cast"](addr, pointerType).ptr();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div>};</div><div><br class="webkit-block-placeholder"></div><div><div>BOOST_PYTHON_MODULE(math)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>to_python_converter<float *, ctypes_float_ptr>();</div>
<div><br class="webkit-block-placeholder"></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>class_<Matrix>("Matrix")</div><div><div><span class="Apple-tab-span" style="white-space: pre; ">                </span>.def("test", &Matrix::test) // this compiles fine</div>
</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>.def("ptr", &Matrix::ptr) // error here</div><div><span class="Apple-style-span" style="white-space: pre; ">        </span></div><div>}</div>
</div><div><br class="webkit-block-placeholder"></div><div>And the error is as follows:</div><div><br class="webkit-block-placeholder"></div><div>src/math.cpp:146: error: no matching function for call to 'boost::python::class_<math::Matrix, boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified>::def(const char [4], <unknown type>)'</div>
<div><br class="webkit-block-placeholder"></div><div>Any pointers on where to go from here?</div><div><br class="webkit-block-placeholder"></div><div><span class="gmail_quote">On 26/02/2008, <b class="gmail_sendername">Joseph Lisee</b> <<a href="mailto:jlisee@gmail.com">jlisee@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
> Thank you for the prompt answer - that accomplishes exactly what I was trying<br> to do!<br> > I haven't had a lot of luck tracking down the hooks to add a manual conversion<br> for 'float *' into the types registry, do you have any reference for that handy?<br>
><br> > - Tristam<br> <br> <br>No problem, I think this is what you are looking for:<br> <a href="http://www.boost.org/libs/python/doc/v2/to_python_converter.html">http://www.boost.org/libs/python/doc/v2/to_python_converter.html</a><br>
<br><br> -Joseph Lisee<br> <br><br> _______________________________________________<br> C++-sig mailing list<br> <a href="mailto:C++-sig@python.org">C++-sig@python.org</a><br> <a href="http://mail.python.org/mailman/listinfo/c++-sig">http://mail.python.org/mailman/listinfo/c++-sig</a><br>
</blockquote></div><br> </div>