我尝试使用 SWIG 扩展一个 Matrix 类来创建一个 python 接口。我使用了官方的Docu代码。但是我收到一条完全荒谬的错误消息。我在哪里声明我的行类似乎并不重要。编译时总是出现这个错误。SWIG 有什么问题?
错误:
ANPyNetCPUPYTHON_wrap.cxx: In function ‘ANN::F2DArray ANN_F2DArray___getitem__(ANN::F2DArray*, int)’:
ANPyNetCPUPYTHON_wrap.cxx:5192: error: ‘Grid2dRow’ was not declared in this scope
ANPyNetCPUPYTHON_wrap.cxx:5192: error: expected `;' before ‘r’
ANPyNetCPUPYTHON_wrap.cxx:5193: error: ‘r’ was not declared in this scope
代码:
%{
#include <AN2DArray.h>
%}
%include <AN2DArray.h>
%inline %{
struct Grid2dRow {
ANN::F2DArray *g; // Grid
int y; // Row number
// These functions are used by Python to access sequence types (lists, tuples, ...)
float __getitem__(int x) {
return g->GetValue(x, y);
}
void __setitem__(int x, float val) {
g->SetValue(x, y, val);
}
};
%}
%extend ANN::F2DArray
{
ANN::F2DArray __getitem__(int y) {
Grid2dRow r;
r.g = self;
r.y = y;
return r;
}
};