SWIG 不包装派生类的继承静态函数。如何解决?
这是问题的简单说明。
这是一个简单的 C++ 头文件:
// file test.hpp
#include <iostream>
class B
{
public:
static void stat()
{ std::cerr << "=== calling static function B::stat" << std::endl; }
void nonstat() const
{ std::cerr << "==== calling B::nonstat for some object of B" << std::endl; }
};
class D : public B {};
C++ 源文件只包含头文件:
// file test.cpp
#include "test.hpp"
SWIG 接口文件只包含 C++ 头文件:
// file test.swig
%module test
%{
#include "test.hpp"
%}
%include "test.hpp"
然后我通过以下方式生成 swig 包装器代码:
swig -c++ -tcl8 -namespace main.swig
然后我通过这个创建一个共享库:
g++ -fpic -Wall -pedantic -fno-strict-aliasing \
test.cpp test_wrap.cxx -o libtest.so
因此,当在 tcl 解释器中加载 libtest.so 并尝试使用包装的接口时,它具有以下行为:
% load libtest.so test
% test::B b
% test::D d
% b nonstat # works fine
% d nonstat # works fine
% test::B_stat # works fine
% test::D_stat # DOESN'T WORK !!
所以问题是我怎样才能让 SWIG 包装 D::stat?