How to create SWIG interface file?

自闭症网瘾萝莉.ら 提交于 2019-12-06 07:17:19

Here's an interface file for your example. SWIG has built-in support for std::string and std::complex. You must declare the concrete classes of the templates you want to use via %template:

%module Item

%{
#include "Item.h"
%}

%include <std_string.i>
%include <std_complex.i>
%include "Item.h"
%template(Int) Item<int>;
%template(Complex) Item<std::complex<double> >;

Use it like:

>>> import Item
>>> a=Item.Int('Int1',5)
>>> b=Item.Complex('Cplx1',2+3j)
>>> a.name()
'Int1'
>>> b.name()
'Cplx1'
>>> a.norm()
5.0
>>> b.norm()
3.605551275463989
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!