当我使用int
时,一切正常 -
%immutable S::field;
%typemap(javaout) int S::field {
//custom code
}
struct S {
int field;
};
但方法不适用于std::vector<int>
%include <std_vector.i>
%immutable S::field;
%template(vector_int) std::vector<int>;
%typemap(javaout) std::vector<int> S::field {
//custom code
}
struct S {
std::vector<int> field;
};
使用swig -java -c++ -module sample sample.i
答案 0 :(得分:1)
请参阅structure data members上的Swig文档。
关键点是:
当结构成员被包装时,它被作为指针处理,除非使用
%naturalvar
指令处理它更像C ++引用。
所以你需要定义的类型图是
%typemap(javaout) std::vector<int>* S::field {
//custom code
}
(如果您使用的是%typemap(javaout) std::vector<int>& S::field
,则为%naturalvar
。