Próbuję uzyskać Boost Python ładnie grać z std :: shared_ptr. Obecnie otrzymuję ten błąd:Korzystanie z Boost Python & std :: shared_ptr
Traceback (most recent call last):
File "test.py", line 13, in <module>
comp.place_annotation(circle.centre())
TypeError: No to_python (by-value) converter found for C++ type: std::shared_ptr<cgl::Anchor>
Od wywołania circle.centre(), które zwraca std :: shared_ptr. Mógłbym zmienić każdy std :: shared_ptr na boost :: shared_ptr (z którym ładnie Python ładnie się odtwarza), jednak ilość kodu do zmiany jest całkiem spora i chciałbym użyć standardowej biblioteki.
Metoda koło jest zadeklarowana następująco:
const std::shared_ptr<Anchor> centre() const
{
return Centre;
}
Klasa kotwica tak:
class Anchor
{
Point Where;
Annotation* Parent;
public:
Anchor(Annotation* parent) :
Parent(parent)
{
// Do nothing.
}
void update(const Renderer& renderer)
{
if(Parent)
{
Parent->update(renderer);
}
}
void set(Point point)
{
Where = point;
}
Point where() const
{
return Where;
}
};
i odpowiedni kod doładowania Python jest:
class_<Circle, bases<Annotation> >("Circle", init<float>())
.def("radius", &Circle::radius)
.def("set_radius", &Circle::set_radius)
.def("diameter", &Circle::diameter)
.def("top_left", &Circle::top_left)
.def("centre", &Circle::centre);
// The anchor base class.
class_<Anchor, boost::noncopyable>("Anchor", no_init)
.def("where", &Anchor::where);
jestem za pomocą Boost 1.48.0. Jakieś pomysły?
try 'class_> ("Anchor", no_init)' –
kassak
@kassak I” próbowałem tego, ten sam problem. –
Dokumentacja swig ma pewne objaśnienie na temat zawijania inteligentnych wskaźników, które mogą być pomocne. –