使用SWIG::包装基本Python

2024-09-29 20:27:37 发布

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

我很惊讶地发现下面的函数不是由SWIG自动包装的。当然,我一定做错了什么,因为这是一个非常基本的例子。在

接口文件(stdmap.i):

%module stdmap;

%include "std_map.i"
%template(map_ii) std::map<int, int>;

%{
    extern std::map<int, int> test_map();
%}
extern std::map<int, int> test_map();

实现(stdmap.cpp):

^{pr2}$

当包装到Python时,我得到

> test_map()
<stdmap.map_ii; proxy of <Swig Object of type 'std::map< int,int > *' at 0x10801dd50> >

而不是

{1: 0, 4: 5}

一如预期。我在哪里出错?在


Tags: 文件of函数testmapincludeexterntemplate

热门问题