I’m writing a wrapper class for an abstract base class, the base class has a couple of pure virtual methods and an overloaded operator, if I compile with the overloaded operator I get the following error:
cannot allocate an object of abstract type
Even though I implement the overloaded operator in my wrapper class, somehow Boost.Python still insists that it is not implemented, any clue ?
This is what my code looks like:
//abstract base class
class Test
{
public:
virtual void start() = 0;
virtual void stop() = 0;
virtual bool operator==(const Test rhs) = 0;
};
//wrapper class
struct TestWrapper: Test, wrapper<Test>
{
public:
void start()
{
this->get_override("start")();
}
void stop()
{
this->get_override("stop")();
}
bool operator==(const Test& rhs)
{
return this->get_override("operator==")(rhs);
}
};
//boost python module
class_<TestWrapper, boost::noncopyable>("Test")
.def("start", pure_virtual(&Test::start) )
.def("stop", pure_virtual(&Test::stop) )
.def("operator==", pure_virtual(&Test::operator==))
;
Edit: I’m not even sure this is the right way to do this, I haven’t seen any examples like this in the docs.
You’ve got two different signatures:
In the derived class:
So you’re not actually implementing the pure virtual from the base, but rather defining a new function.