17
我用SWIG來包裝我的C++類。有些方法將const std::string&
作爲參數。 SWIG會創建一個名爲SWIGTYPE_p_std__string
的類型,但是在調用c#中的方法時,您不能只爲此傳遞一個普通字符串。下面的例子只是附帶SWIG包:將SWIG與採用std :: string作爲參數的方法結合使用
public void setName(SWIGTYPE_p_std__string name)
{
examplePINVOKE.Shape_setName(swigCPtr, SWIGTYPE_p_std__string.getCPtr(name));
if (examplePINVOKE.SWIGPendingException.Pending) throw examplePINVOKE.SWIGPendingException.Retrieve();
}
以我接口文件I只是有一個變形例:
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Let's just grab the original header file here */
%include "example.h"
,並且該方法被包裝在C++是:
void Shape::setName(const std::string& name)
{
mName = name;
}
是否有某種typemap我必須放在接口文件中?如果是這樣,我該怎麼做?