迭代boost::python vector_indexing_sui时出现意外结果

2024-05-20 17:09:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我成功地包装了一个名为Composite的类。 此类具有以下方法:

std::vector<Composite*> Composite::getChildren();

我尝试使用vector_indexing_套件包装返回的std::vector,方法是: [片段]

^{pr2}$

现在一切似乎都正常工作,当我从python调用getChildren()方法时,它会正确地返回一个包装好的CompositeArray。我可以做,例如:

from composite import Composite
myComp = Composite()

myComp.addChild('childA')
myComp.addChild('childB')

len(myComp.getChildren())  #returns 2
myComp.getChildren()[0] # returns the first child of type Composite

但是当我尝试迭代compositeRay时,比如这样:

for child in myComp.getChildren():
    # do something with child...

我收到了这个错误消息:

TypeError: No to_python (by-value) converter found for C++ type: class Composite * __ptr64

这对我来说没有任何意义,考虑到按索引访问非常有效! 我被困住了。。。你知道我做错了什么吗?在

谢谢。在


Tags: 方法childfor套件typereturnsstdvector