SWIGを使用してC ++インスタンスをsast化するオブジェクトをPythonで作成したいと思います。
次のような例があり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"
もちろん、上記は問題なくコンパイルされます。私はiCat
Pythonでを作成しようとするために以下を書きました、すなわち:
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"
正常に動作します。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加