I have a c++ class with a pure virtual function which I wrap in the following way using Boost Python:
class Model {
virtual double Test() = 0;
};
class ModelWrapper : public Model, public boost::python::wrapper<Model> {
double Test() {
return this->get_override("Test")();
}
};
BOOST_PYTHON_MODULE(mymodule)
{
class_<ModelWrapper, boost::noncopyable>("Model")
.def("Test, pure_virtual(&Model::Test))
;
}
I also have a c++ function that's expecting a Model object as an argument:
double MyFunction(Model& m) {
return m.Test()
}
Now what I would like to do is to make a derived class in Python that overrides the Model::Test function but can still be passed to MyFunction. Something like this:
from mymodule import *
class NewModel(Model):
def Test(self):
return 0.5
m = NewModel()
print(MyFunction(m))
which I would want to print out 0.5 in this case. Instead I get this error:
> ArgumentError: Python argument types in
> mymodule.MyFunction(NewModel) did not match C++ signature:
> MyFunction(Model {lvalue})
I'm not sure what step I'm missing in order for NewModel to be usable where Model is expected. Any insight would be greatly appreciated.