我不太会喝酒。我已经创建了一个python模块来使用c++类。在
我的cpp标题代码是
等级复杂度.h:
class GradedComplex
{
public:
typedef std::complex<double> dcomplex;
typedef Item<dcomplex> item_type;
typedef ItemComparator<dcomplex> comparator;
typedef std::set<item_type, comparator> grade_type;
private:
int n_;
std::vector<grade_type *> grade_;
std::vector<double> thre_;
public:
GradedComplex(int n, double *thre);
~GradedComplex();
void push(item_type item);
void avg(double *buf);
};
CPP代码是
^{pr2}$我的SWIG接口文件是:
例子。我
/* File: example.i */
%module example
%{
#include "Item.h"
#include "GradedComplex.h"
#include "GradedDouble.h"
%}
%include <std_string.i>
%include <std_complex.i>
%include "Item.h"
%include "GradedComplex.h"
%include "GradedDouble.h"
%template(Int) Item<int>;
%template(Complex) Item<std::complex<double> >;
我通过运行*python生成了python模块设置.pybuild\u ext--inplace*此命令。在
现在我想从python访问GradedComplex(intn,double*thre)
当我试图访问GradedComplex时,它显示 **TypeError:在方法“new\u GradedComplex”中,类型为“double”的参数2错误*
如何从python模块传递双指针?请帮我整理一下。在
直接在构造函数中使用向量并利用SWIG的向量支持更简单:
在
.i
文件中:在
^{pr2}$.h
中:在
.cpp
中:n_
可以消失,因为{称之为:
SWIG也可以处理返回向量,因此
avg
可以是:相关问题 更多 >
编程相关推荐