cython - 用嵌套类型包装 C++ 类
问题描述
官方文档显示了一个Rectangle.h
仅包含原始类型的示例。
如果如何包装这个类
Rectangle.cpp
本身使用了Blabla.h
哪些定义BlaBla getBla(int x, BlaBla* ptr)
- 这将是
Rectangle.h
.
如果我用 Cython 编译它,我会收到以下Unknown type
错误Blabla
:
问:如何告诉 Cython 在哪里可以找到BlaBla
?我是否也需要编写自定义包装器BlaBla
?
一个例子:
#ifndef RECTANGLE_H
#define RECTANGLE_H
#include "Blabla.h" // This is the addition from the official example
namespace shapes {
class Rectangle {
public:
int x0, y0, x1, y1;
Rectangle();
Rectangle(int x0, int y0, int x1, int y1);
~Rectangle();
int getArea();
void getSize(int* width, int* height);
void move(int dx, int dy);
// New method:
BlaBla getBla(int x, BlaBla* ptr);
};
}
#endif
有陪伴.pxd
cdef extern from "Rectangle.h" namespace "shapes":
cdef cppclass Rectangle:
Rectangle() except +
Rectangle(int, int, int, int) except +
int x0, y0, x1, y1
int getArea()
void getSize(int* width, int* height)
void move(int, int)
// New:
BlaBla getBla(int x, BlaBla* ptr);
Cython 会抱怨自己BlaBla
是一个无法识别的类型
解决方案
推荐阅读
- ios - 将多个请求合并为一个。将 observable 数组转换为数组的 observable
- mysql - 从派生表名中返回所有也有 IN 语句的记录
- c# - 在 WPF XAML 中,如何动态创建与索引属性的双向绑定?
- java - 拖动视图 onLongClick 并启动活动 onClick
- kubernetes - Kubernetes 节点内存限制
- javascript - 使用 Node Selenium 下载 Excel 文件
- shell - 用于创建 Hive 表的 Shell 脚本
- python - 无法设置竞争条件,我的代码是否按顺序运行?
- python - 如何在python环境中的linux文件中的特定模式或行号之后添加多行
- css - 悬停效果不支持 p 和 h1 标签