在boost::python向量上迭代时出现TypeError
我得到了一个非常类似的问题,如:在boost::python向量上迭代时出现TypeError,python,c++,boost,stdvector,Python,C++,Boost,Stdvector,我得到了一个非常类似的问题,如: 我有以下C++代码: #include <vector> #include <boost/python.hpp> #include <boost/python/suite/indexing/vector_indexing_suite.hpp> using namespace boost::python; class Composite { public: std::string name;
我有以下C++代码:
#include <vector>
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
using namespace boost::python;
class Composite {
public:
std::string name;
std::vector<Composite*>& getChildren() {
return children;
};
std::vector<Composite*> children;
};
typedef std::vector<Composite*> CompositeArray;
BOOST_PYTHON_MODULE(coin)
{
class_<CompositeArray>("CompositeArray")
.def(vector_indexing_suite<CompositeArray, true>());
class_<Composite>("Composite", "Composite*", init<>())
.def("getChildren", &Composite::getChildren, return_internal_reference<>())
.def_readwrite("name", &Composite::name, "str")
;
}
产生错误:
Traceback (most recent call last):
File "gna.py", line 34, in <module>
for prout in gna.getChildren():
TypeError: No to_python (by-value) converter found for C++ type: class Composite * __ptr64
回溯(最近一次呼叫最后一次):
文件“gna.py”,第34行,在
对于gna.getChildren()中的prout:
TypeError:没有C++的TyPython(按值)转换器:类复合**pTr64
这在Boost 1.59中运行良好,但在Boost 1.60中不再如此
有什么想法吗
编辑:
我尝试更新(见下面的建议):
类(“复合”、“复合*”,init())
致:
类(“复合”、“复合*”,init())
我确认它正在使用boost 1.59,但不是boost 1.60。
class_<Composite>("Composite", "Composite*", init<>())
类(“复合”、“复合*”,init())
到
类(“复合”、“复合*”,init())
boost 1.55帮助了我。我可以找到任何解决这个问题的“好”解决方案,并将所有原始指针迁移到std::shared_ptr以使其工作。这里讨论这个问题:
在这里:
也不适用于1.55。当我编写“class_3;”时,无论是boost1.59还是boost1.60,我都没有收到任何错误消息。我用gcc-4.8.4和python3.4编译了boost。也许,您的安装或编译命令有问题。您可以向我们展示您的命令吗?我正在使用Visual Studio 2013和Python 3.3.5。我将尝试使用更新的Python。您仍然对VS中的编译行感兴趣吗?不幸的是,它也不适用于Python 3.5.1。所以这将是一个Windows回归只?谢谢!不幸的是,它仍然不能在这里工作。你可能是对的,我在建造我的复制机时错过了一些东西。现在我确信我有一些东西可以使用boost 1.59,而不是boost 1.60。
class_<Composite>("Composite", "Composite*", init<>())
class_<Composite, Composite*>("Composite", "Composite*", init<>())
class_<Composite>("Composite", "Composite*", init<>())
class_<Composite, Composite*>("Composite", "Composite*", init<>())