我使用 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;
}
我是否必须在界面文件中放入某种类型映射?如果是这样,我该怎么做?
当我发现你的问题时,我正在尝试自己解决这个问题。
您需要包括
%include "std_string.i"
in your .i
文件。看:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)