[英]Cannot expose private base class member functions in SWIG wrapper
I'm wrapping some C++ code with SWIG for an Android application. 我将SWIG包装一些C ++代码用于Android应用程序。 I'm facing an issue when I use a class that privately inherit from another, and throw a couple of
using
directive in there to expose some of the parent's member functions. 当我使用一个从另一个私有继承的类,并在其中抛出几个
using
指令来公开某些父级的成员函数时,我遇到了一个问题。 Looks like this: 看起来像这样:
#include "Bar.h"
class Foo : private Bar {
//Stuff Foo-specific...
public:
using Bar::baz;
};
The thing is, when I run SWIG, I get the following message during the wrapping: 问题是,当我运行SWIG时,在包装过程中会收到以下消息:
Foo.h:8: Warning 315: Nothing known about 'Bar::baz()'.
Foo.h:8:警告315:“ Bar :: baz()”一无所知。
Note: Both headers are included in the wrapper file, only the Foo
header is wrapped, as I don't want the Bar
header to be wrapped, my .i
file looks like: 注意:这两个标头都包含在包装文件中,只包装了
Foo
标头,因为我不希望包装Bar
标头,因此我的.i
文件看起来像:
%{
#include "Bar.h"
#include "Foo.h"
%}
%include "Foo.h"
Then, my Java class doesn't compile because it cannot find this symbol... 然后,我的Java类无法编译,因为找不到该符号...
I read in the SWIG documentation that private inheritance and the using
keyword (although there isn't an example about private inheritance) are supposed to be supported, so what am I missing here? 我在SWIG文档中读到应该支持私有继承和
using
关键字 (尽管没有关于私有继承的示例),所以我在这里遗漏了什么?
First, your using
statement should be using Bar::baz;
首先,您的
using
语句应using Bar::baz;
. 。
Anyway, as SWIG says in the warning, it cannot wrap Foo::baz()
if it does not know the declaration in Bar::baz()
. 无论如何,正如SWIG在警告中所说,如果它不知道
Bar::baz()
的声明,它就不能包装Foo::baz()
Bar::baz()
。
Therefore, you need to show the declaration to SWIG, eg, by an %include "Bar.h"
directive. 因此,您需要向SWIG显示声明,例如,通过
%include "Bar.h"
指令。 If you do not want Bar
to be wrapped, you can use an additional %ignore Bar;
如果您不希望包装
Bar
,则可以使用其他%ignore Bar;
directive. 指示。
Here is a minimal working example: 这是一个最小的工作示例:
%ignore Bar;
%inline %{
class Bar {
public:
double baz() { return 4.2; }
};
class Foo : private Bar {
public:
using Bar::baz;
};
%}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.