我使用SWIG封装了我的c++类。一些方法的参数是const std::string&
类型。 SWIG创建了一个名为SWIGTYPE_p_std__string
的类型,但是在C#中调用该方法时,您不能仅仅传递一个普通字符串。以下示例只是SWIG包中的一个修改后的示例:
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();
}
在我的接口文件中,我只有:
/* 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;
}
我需要在接口文件中放置某种类型映射吗?如果是这样,我该如何做到呢?