<span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse">Hi all,<div><br></div><div>I am new to boost.python (and relatively new to python) so my question might be rather simple (or stupid).</div>
<div><br></div><div>I have an abstract C++ base class and a derived class DerivedA which I exposed to Python. Works beautifully</div><div><br></div><div>class Base</div><div>{</div><div>public:</div><div> virtual double compute(void) = 0;</div>
<div>}; </div><div><br></div><div><div>class DerivedA : public Base</div><div>{</div><div>public:</div><div> virtual double compute(void) { return 5.0; }</div><div>}; </div><div><br></div><div>added my own DerivedB in python</div>
<div><div>class DerivedB(Base):</div><div> def compute(self):</div><div> return 25.0;</div><div><br></div><div>which also works.</div><div><div>>>> d_a = DerivedA() // my C++ derived class; works fine</div>
<div>>>> d_b = DerivedB() // my python derived class; works fine</div><div><div>>>> d_a.compute() // works fine</div><div>5.0</div><div>>>> d_b.compute() // works fine</div><div>25.0</div>
<div><br></div></div></div><div>Now I have added a funtion testBase in C++ which looks as follows</div><div><div>double testBase(Base* b)</div><div>{</div><div> return b->compute() + 11.5;</div><div>}</div><div><br>
</div><div>which I exposed to python using (with help of Py++)</div><div><br></div><div><div> typedef double (*testBase_function_type)(Base *);</div><div> </div><div>def("testBase", testBase_function_type( &::testBase ),</div>
<div> ( arg("b") ) );</div><div><br></div></div></div><div>What I was hoping to work was</div><div><br></div><div><div>>>> testBase(d_a) // on the derivedA C++ class</div><div>Traceback (most recent call last):</div>
<div>ArgumentError: Python argument types in</div><div> hello.testBase(DerivedA)</div><div>did not match C++ signature:</div><div> testBase(class Base * b)</div><div><br></div><div>does not work. Any help would be appreciated.</div>
<div>My more general aim is to write C++ code in terms of abstract base classes. From time to time I need to derive classes in python from the abstract base classes, but I would still like to be able to use the functions written in terms of the C++ base classes. How would I need to go about that using boost.python</div>
<div><br></div><div>Thanks,</div><div>Mike </div></div></div></div></span>