SWIG董事的继承

时间:2015-04-21 00:55:56

标签: c++ swig

当我为继承自B类的A类创建SWIG Director时,当C ++库尝试调用B类的方法时,它会失败。

libc++abi.dylib: terminating with uncaught exception of type Swig::DirectorMethodException: SWIG director method error. Error detected when calling 'B.MethodB'

对于具有多级继承的类,SWIG Director是否有任何限制?

更新:下面的实际代码

class RefCountInterface {
 public:
  virtual int AddRef() = 0;
  virtual int Release() = 0;
 protected:
  virtual ~RefCountInterface() {}
};

class SessionObserver : public RefCountInterface {
 public:
  virtual void OnSuccess() = 0;
  virtual void OnFailure() = 0;

 protected:
  ~SessionObserver() {}
};

void CreateOffer(SessionObserver* observer); // This ends up calling observer->Release and that raises the exception

%module(directors="1") module
%feature("director") SessionObserver;

Python代码:

class MySessionObserver(module.SessionObserver):
    def __init__(self, *args, **kwargs):
        module.SessionObserver.__init__(self, *args, **kwargs)
        self.count = 1

    def AddRef(self):
        self.count += 1
        return self.count

    def Release(self):
        self.count -= 1
        return self.count

    def OnSuccess(self, desc):
        print "OnSuccess"

    def OnFailure(self, err):
        print "OnFailure"

0 个答案:

没有答案