【发布时间】:2012-02-03 01:20:58
【问题描述】:
我使用 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;
}
我必须在接口文件中放入某种类型的映射吗?如果是这样,我该怎么做?
【问题讨论】: