带有虚拟纯接口的 SWIG c#

SWIG c# with a virtual pure interface

我正在尝试使用 SWIG 将 C++ 虚拟纯接口包装到 c# 中。 这是我的 dll C++ 接口:

class EXPORT FeatureItf
{
protected:
    virtual ~FeatureItf() { }
public:
    virtual void PrintMe() = 0;
    virtual void Delete() = 0;
};

bool EXPORT FeatureItfCreator(FeatureItf*& feat);

对于链接 dll 的 C++ 用户,API 很简单:

FeatureItf* feat = nullptr;
FeatureItfCreator(feat); // will allocate feat
feat->PrintMe();
feat->Delete();

如何使用 SWIG 将 FeatureItf class 包装到 c# class 中? 特别是管理 creator 函数中的 *& 和 c# 对象上的构造。

这很好用:

%include swigtype_inout.i
%apply SWIGTYPE *& OUTPUT { SWIGTYPE *& }