如何制作一个满足SWIG中接口的python类
How do I make a python class satisfying an interface in SWIG?
我想在Python中创建一个对象,使用SWIG作为C++实例。
假设我有一个类似Example.h
:的例子
struct iCat
{
virtual int paws() const = 0;
};
int pawGiver(const iCat& cat);
struct cat : public iCat
{
int paws() const
{
return 4;
}
};
和Example.cpp
:
#include "Example.h"
int pawGiver(const iCat& cat)
{
return cat.paws();
}
和example.i
:
/* File : example.i */
%module example
%{
#include "Example.h"
%}
%include "Example.h"
当然,以上内容汇编得很好。我写了以下内容,试图用Python制作iCat
,即:
import example;
class pyCat(example.iCat):
def __init__(self):
super().__init__()
def paws(self):
return 3;
z = pyCat()
example.pawGiver(z)
我想做的事情有可能吗?Python类可以实现C++实例吗?我做错了什么?
很简单。将界面修改为:
/* File : example.i */
%module(directors="1") example
%{
#include "Example.h"
%}
%feature("director");
%include "Example.h"
运行良好。
相关文章:
- 为重写std::exception的库生成swig接口时出错
- 分解SWIG Python接口 - 容器会产生命名空间冲突
- 如何制作一个满足SWIG中接口的python类
- 如何使用 SWIG 接口访问 python 中的 C++ typedef'd 结构
- 如何在SWIG接口文件中检查Lua版本
- 如何编写swig接口文件
- 通过SWIG禁用python-c 接口的隐式类型检查代码
- swig:接口简单的C 类,返回向量
- 如何使用SWIG中的相同接口生成两个代理类
- 如何为使用矢量的函数编写 SWIG 接口文件<string>?
- C++ 以指针作为参数的函数,并使用 swig 接口处理它
- 通过数据序列化的SWIG接口
- 使用SWIG将C++代码与perl接口
- swig接口文件的正确sstream include路径是什么
- 使用SWIG为perl创建C++接口
- 使用SWIG实现c++和Python的接口
- 如何将 Boost::shared_ptr 暴露到<T> Tcl + SWIG 接口文件?
- 向SWIG python接口返回字符串的最佳方法是什么?
- 是否可以禁止在 "truly lazy" SWIG 接口文件中包含类/函数?
- 在swig接口中解引用boost::shared_ptr的好方法