如何在SWIG中为c++;? 我在C++文件中有一个具有以下签名的模板函数 template <class T> std::vector<T> function(T); 模板std::向量函数(T);

如何在SWIG中为c++;? 我在C++文件中有一个具有以下签名的模板函数 template <class T> std::vector<T> function(T); 模板std::向量函数(T);,c++,python-2.7,swig,C++,Python 2.7,Swig,我想制作一个接口文件,用Swig将main.cpp包装成python文件。 对于int float和double类型,我应该如何在Swig中包含Tfunction //main.i %module main %include "carrays.i" %array_class(double, doubleArray); %{ extern template <class T> std::vector<T> Tfunction(T); %} extern templ

我想制作一个接口文件,用Swig将main.cpp包装成python文件。 对于int float和double类型,我应该如何在Swig中包含Tfunction

//main.i
%module main
%include "carrays.i"
%array_class(double, doubleArray);

%{
   extern template <class T> std::vector<T> Tfunction(T);
%}

extern template <class T> std::vector<T> Tfunction(T);
//main.i
%主模块
%包括“carrays.i”
%数组_类(双数组、双数组);
%{
外部模板std::向量T函数(T);
%}
外部模板std::向量T函数(T);

因为Python不知道模板,所以必须为每个参数创建一个类型。您可以使用一个方便的%模板指令:

%template(TfunctionInt) Tfunction<int>;
%模板(TfunctionInt)Tfunction;
这将在中详细解释