我试图将int(C++)的STL映射(版本3)向类指针,到Python 3:
示例.h
#include <map>
using namespace std;
class Test{};
class Example{
public:
map<int,Test*> my_map;
Example()
{
int a=0;
Test *b = new Test();
this->my_map[a] = b;
}
};
示例。i
^{pr2}$没有错误,但是现在在python3中,运行
import example
t = example.Example()
t.my_map
退货
<Swig Object of type 'map< int,Test * > *' at 0x10135e7b0>
而不是字典。它还有一个指向地图的指针,而不是一个地图。如何编写正确的%typemap
将STL映射转换为python3字典?在
我已经能够为例如int到int的映射这样做-它是一个类的指针给我带来麻烦。在
谢谢。在
让我从SWIG手册中为您提供相关条目。。。here
这告诉您成员变量
my_map
是通过SWIG生成的getter访问的,getter返回一个map<int,Test*> *
(或者引用,如果您给出%naturalvar
指令)。因此,必须编写out typemap来处理map<int,Test*> *
,而不是map<int,Test*>
。在相关问题 更多 >
编程相关推荐