我正在尝试使用Swig包装一个C ++库,并且我遇到了一个重载方法的问题(并且我在18年内没有触及过C ++也没有帮助)。
这是一个非常简化的类结构:
class TView : public TObject, public TStreamable {
public:
virtual TPalette& getPalette() const;
}
class TGroup : public TView {
// ...
}
class TWindow: public TGroup {
virtual TPalette& getPalette() const;
}
swig文件(再次,简化,看起来像这样):
%module(directors="1") tvision
%feature("director") TApplication;
%feature("director") TProgram;
%feature("director") TProgInit;
%feature("director") TWindow;
%feature("director") TWindowInit;
%feature("director") TView;
%feature("director") TGroup;
// Obviously a shotgun approach hoping one of these works :P
%rename ("$ignore") TWindow::getPalette;
%ignore TWindow::getPalette;
%rename ("getPalette2") "TWindow::getPalette";
//...
%include "tv/view.h"
%include "tv/group.h"
%include "tv/window.h"
当我生成Java包装器并尝试编译它时,我收到此错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project tvsample: Compilation failure: Compilation failure:
[ERROR] /home/jdlee/src/turbovision/swig/src/generated/java/com/steeplesoft/turbovision/internal/tvisionJNI.java:[1348,45] incompatible types: short cannot be converted to com.steeplesoft.turbovision.internal.TPalette
[ERROR] /home/jdlee/src/turbovision/swig/src/generated/java/com/steeplesoft/turbovision/internal/TWindow.java:[129,16] getPalette() in com.steeplesoft.turbovision.internal.TWindow cannot override getPalette() in com.steeplesoft.turbovision.internal.TView
[ERROR] return type short is not compatible with com.steeplesoft.turbovision.internal.TPalette
两件事。首先应该忽略TWindow :: getPalette,但事实并非如此。第二个是SWIG正在生成这个Java方法:
public short getNumber() {
return tvisionJNI.TWindow_number_get(swigCPtr, this);
}
是否有人对这两个问题都有答案?理想情况下,应该有一个返回TPalette的TWindow#getPalette()方法。如果我可以修复它,它可能会修复忽略问题,因为我只是试图忽略该方法,看看我是否可以通过编译问题。
帮助?请? :)