Swig:使用c++;Python中的STL复合体 我想在Python中使用C++复杂类型。我尝试了以下Swig接口文件: %module example %include <std_complex.i> %template(c

Swig:使用c++;Python中的STL复合体 我想在Python中使用C++复杂类型。我尝试了以下Swig接口文件: %module example %include <std_complex.i> %template(c,python,c++,swig,Python,C++,Swig,Swig:使用c++;Python中的STL复合体 我想在Python中使用C++复杂类型。我尝试了以下Swig接口文件: %module example %include <std_complex.i> %template(complexf) std::complex<float>; 如果我手动包含C++头文件, %module example %include <std_complex.i> %include "/usr/include

Swig:使用c++;Python中的STL复合体

我想在Python中使用C++复杂类型。我尝试了以下Swig接口文件:

%module example
%include <std_complex.i>
%template(complexf) std::complex<float>;

如果我手动包含C++头文件,

%module example
%include <std_complex.i>

%include "/usr/include/c++/7/complex"
%template(complexf) std::complex<float>;

>我想知道如何正确使用C++的SWIG复合物?

< > >代码> STDYFALL。I < /代码>已经包含足够的定义,使用<代码> STD::复合< /代码>:


谢谢我很感激。
%module example
%include <std_complex.i>

%include "/usr/include/c++/7/complex"
%template(complexf) std::complex<float>;
/usr/include/c++/7/complex:50: Error: Syntax error in input(1).
%module example
%include <std_complex.i>

%inline %{
using complexf = std::complex<float>;
complexf func(complexf a, complexf b)
{
    return a + b;
}
%}
>>> import example
>>> example.func(1+2j,3-4j)
(4-2j)