Hello,
I'm getting a seg fault when trying to call a virtual method on a base class
from python. Code is below:
#include <memory>
namespace boost {
template<class T> const T* get_pointer(const std::shared_ptr<T>& ptr)
{
return ptr.get();
}
template<class T> T* get_pointer(std::shared_ptr<T>& ptr)
{
return ptr.get();
}
}
#include <Python.h>
#include <boost/python.hpp>
namespace bp = boost::python;
class MyBase
{
public:
MyBase(){}
virtual ~MyBase(){}
virtual void baseTest() { printf("base test\n"); }
};
class MyDerived : public MyBase
{
public:
MyDerived() {}
virtual ~MyDerived(){}
void derivedTest() { printf("derived test\n"); }
};
BOOST_PYTHON_MODULE(PythonTest)
{
bp::class_<MyBase, std::shared_ptr<MyBase>>("MyBase")
.def("baseTest", &MyBase::baseTest);
bp::class_<MyDerived, bp::bases<MyBase>,
std::shared_ptr<MyDerived>>("MyDerived")
.def("derivedTest", &MyDerived::derivedTest);
bp::implicitly_convertible<std::shared_ptr<MyDerived>,
std::shared_ptr<MyBase>>();
}
Does it have to do with using std::shared_ptr for storage? If so is there a
way around this? Any help is appreciated.
--
Gabe Rives-Corbett
_______________________________________________
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig