Vah*_*agn 5 c++ inheritance swig tcl static-functions
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 {};
Run Code Online (Sandbox Code Playgroud)
C ++源文件仅包含头文件:
// file test.cpp
#include "test.hpp"
Run Code Online (Sandbox Code Playgroud)
SWIG接口文件仅包含C ++头文件:
// file test.swig
%module test
%{
#include "test.hpp"
%}
%include "test.hpp"
Run Code Online (Sandbox Code Playgroud)
然后,我以此生成swig包装器代码:
swig -c++ -tcl8 -namespace main.swig
Run Code Online (Sandbox Code Playgroud)
然后我以此创建一个共享库:
g++ -fpic -Wall -pedantic -fno-strict-aliasing \
test.cpp test_wrap.cxx -o libtest.so
Run Code Online (Sandbox Code Playgroud)
因此,当在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 !!
Run Code Online (Sandbox Code Playgroud)
所以问题是如何使SWIG包装D :: stat?
静态函数只在父级中定义class B正确吗?如:
D::stat();
Run Code Online (Sandbox Code Playgroud)
可调用不正确吗?这就是为什么 SWIG 不包装该函数的原因......
至于如何访问该函数,SWIG 允许您添加/隐藏/包装任何您想要的类中的函数,因此可以“修复”SWIG 类以提供对stat().
相信语法是这样的:
%extend D {
...
}
Run Code Online (Sandbox Code Playgroud)
自从我接触 SWIG 以来已经有一段时间了,所以我可能记错了一些东西。
| 归档时间: |
|
| 查看次数: |
1387 次 |
| 最近记录: |