小编Bar*_*aum的帖子

如何创建一个可以接收c ++ struct/instance或python对象作为参数的公共cython函数?

我的Rectangle.h

namespace shapes {
    class Rectangle {
    public:
        int x0, y0, x1, y1;
        Rectangle();
        Rectangle(int x0, int y0, int x1, int y1);
        ~Rectangle();
        int getArea();
    };
}
Run Code Online (Sandbox Code Playgroud)

我的Rectangle.cpp

#include "Rectangle.h"
namespace shapes {
  Rectangle::Rectangle() { }
    Rectangle::Rectangle(int X0, int Y0, int X1, int Y1) {
        x0 = X0;
        y0 = Y0;
        x1 = X1;
        y1 = Y1;
    }
    Rectangle::~Rectangle() { }
    int Rectangle::getArea() {
        return (x1 - x0) * (y1 - y0);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的rect.pyx

# distutils: language = c++ …
Run Code Online (Sandbox Code Playgroud)

c++ python struct cython

5
推荐指数
1
解决办法
433
查看次数

标签 统计

c++ ×1

cython ×1

python ×1

struct ×1