Reputation: 2572
I have a C++ object that is the child of a virtual class, and I am trying to wrap in python. The file compiles, and I can import it into python, but when I try to call the function, I get an error:
In [3]: x
Out[3]: <beh.MappedBehaviourDomain at 0x23e7158>
//So, obviously the constructor is working (or at least thinks it is)
In [4]: x.subject_count()
---------------------------------------------------------------------------
ArgumentError Traceback (most recent call last)
/home/max/verk/btr-email/build/x86_64/bin/ipython in <module>()
----> 1 x.subject_count()
ArgumentError: Python argument types in
BehaviourDomainWrap.subject_count(MappedBehaviourDomain)
did not match C++ signature:
subject_count(BehaviourDomainWrap {lvalue})
subject_count(BehaviourDomainWrap {lvalue})
I'm having a hard time understanding this error; this is my first time working with boost python and I don't have much experience with C++. Here's the relevant code:
// Instantiating class for use in boost python
struct BehaviourDomainWrap : BehaviourDomain, wrapper<BehaviourDomain>
{
size_t subjectCount() const {
return this->get_override("subjectCount")();
// A bunch of other methods removed
}
BOOST_PYTHON_MODULE(beh) {
class_<BehaviourDomainWrap, boost::noncopyable>("BehaviourDomainWrap")
.def("subject_count", pure_virtual(& BehaviourDomainWrap::subjectCount))
;
class_<MappedBehaviourDomain, bases<BehaviourDomainWrap> >
("MappedBehaviourDomain", init<std::string>())
;
}
What's going wrong, and why?
Upvotes: 1
Views: 708
Reputation: 2572
I was passing in the wrapped version of the object rather than the base. I should have had:
class_<BehaviourDomainWrap, boost::noncopyable>("beh")
.def("subject_count", pure_virtual(& BehaviourDomain::subjectCount))
;
class_<MappedBehaviourDomain, bases<BehaviourDomain> >
("mapped_beh", init<std::string>())
;
Upvotes: 2