我试图让升压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>
从调用circle.centre(),它返回一个std :: shared_ptr的。 我可以shared_ptr的改变每标准::到一个boost :: shared_ptr的(其升压用Python很好地扮演),但是代码量的改变相当可观的,我想使用标准库。
Circle方法声明如下:
const std::shared_ptr<Anchor> centre() const
{
return Centre;
}
锚类是这样的:
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;
}
};
而相关的升压Python代码是:
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);
我使用升压1.48.0。 有任何想法吗?