Thank you for the fast reply. I would have tried Py++ myself, but I'm unable to install it. I get an error that the .NET framework SDK must be installed in order to build Python extensions when I try to install GCC_XML. I tried to download and install the .NET SDK, but I'm sure if I've really got all of it. I didn't select much for the installation process. Though it is off-topic, any help with this would be nice too. I use Visual Studios C++ express on Windows XP. I have Python
2.4 and the Windows Platform SDK.<br><br>As for the code, I haven't looked at it in a lot of detail yet, but a simple copy-and-paste gives me a run-time error that I'm calling a pure-virtual function when I call Draw() from the passed in Renderable*. Any more thoughts?
<br><br><div><span class="gmail_quote">On 5/5/07, <b class="gmail_sendername">Roman Yakovenko</b> <<a href="mailto:roman.yakovenko@gmail.com">roman.yakovenko@gmail.com</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;">
On 5/5/07, Tom Brooks <<a href="mailto:tgbrooks@gmail.com">tgbrooks@gmail.com</a>> wrote:<br>> I currently have these C++ classes:<br>><br>> class Renderable<br>> {<br>> public:<br>> Renderable();
<br>> virtual ~Renderable();<br>> virtual void Draw() = 0;<br>> };<br>><br>> class Quad : public Renderable<br>> {<br>> public:<br>> Quad(float x, float y, float h, float w);<br>> ~Quad();
<br>> void Draw();<br>> };<br>><br>> And I need to expose them to Python. Then, I need to be able to make one in<br>> Python, and pass it back to a C++ function as a Renderable*.<br>><br>> I made this wrapper class for Renderable:
<br>><br>> struct RenderableWrap : Renderable, wrapper<Renderable><br>> {<br>> public:<br>> void Draw()<br>> {<br>> this->get_override("Draw")();<br>> }<br>> };
<br>><br>> And I have this Boost.Python code for the Python side:<br>><br>> class_<RenderableWrap,<br>> boost::noncopyable>("Renderable")<br>> .def("Draw",pure_virtual(&Renderable::Draw))
<br>> ;<br>><br>> class_<Quad, bases<RenderableWrap> >("Quad",init<float, float, float,<br><br>Quad derives from Renderable, not RenderableWrap<br><br>> float>())<br>> .def("Draw",&Quad::Draw)
<br>> ;<br>><br>> But when I pass in a Quad() to my C++ function, I get an error that it can't<br>> convert from a Quad to a Renderable*. I have next to no clue how the base<br>> class should have been done, since the tutorial and anything else I can find
<br>> online don't go over what to do for the base class (when there are virtual<br>> functions, at least). For example, I don't know if I inherit from<br>> Renderable, or RenderableWrap (or both?). I don't know whether the base
<br>> class needs a wrapper itself (and would it if it had a virtual function?).<br>><br>> I'd appreciate any help!<br><br>Next code was generated by Py++ GUI<br>(<a href="http://language-binding.net/pyplusplus/documentation/tutorials/pyplusplus_gui.html">
http://language-binding.net/pyplusplus/documentation/tutorials/pyplusplus_gui.html</a>)<br><br>#include "boost/python.hpp"<br><br>#include "1.h"<br><br>namespace bp = boost::python;<br><br>struct Renderable_wrapper : Renderable, bp::wrapper< Renderable > {
<br><br> Renderable_wrapper( )<br> : Renderable( )<br> , bp::wrapper< Renderable >(){<br> // null constructor<br><br> }<br><br> virtual void Draw( ){<br> bp::override func_Draw = this->get_override( "Draw" );
<br> func_Draw( );<br> }<br><br>};<br><br>struct Quad_wrapper : Quad, bp::wrapper< Quad > {<br><br> Quad_wrapper(Quad const & arg )<br> : Quad( arg )<br> , bp::wrapper< Quad >(){<br> // copy constructor
<br><br> }<br><br> Quad_wrapper(float x, float y, float h, float w )<br> : Quad( x, y, h, w )<br> , bp::wrapper< Quad >(){<br> // constructor<br><br> }<br><br> virtual void Draw( ) {<br> if( bp::override func_Draw = this->get_override( "Draw" ) )
<br> func_Draw( );<br> else<br> this->Quad::Draw( );<br> }<br><br><br> void default_Draw( ) {<br> Quad::Draw( );<br> }<br><br>};<br><br>BOOST_PYTHON_MODULE(pyplusplus){<br>
bp::class_< Renderable_wrapper, boost::noncopyable >( "Renderable" )<br> .def( bp::init< >() )<br> .def(<br> "Draw"<br> , bp::pure_virtual( &::Renderable::Draw ) );
<br><br> bp::class_< Quad_wrapper, bp::bases< Renderable > >( "Quad",<br>bp::init< float, float, float, float >(( bp::arg("x"), bp::arg("y"),<br>bp::arg("h"), bp::arg("w") )) )
<br> .def(<br> "Draw"<br> , &::Quad::Draw<br> , &Quad_wrapper::default_Draw );<br>}<br><br><br>--<br>Roman Yakovenko<br>C++ Python language binding<br><a href="http://www.language-binding.net/">
http://www.language-binding.net/</a><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>