给定C++函数
void Foo(unsigned int _x, unsigned int _y, std::vector< unsigned int > &_results)
以及将 std::vector 映射到 C# 中类型 VectorUInt32 的 Swig 接口(interface)文件
%include "std_vector.i"
namespace std {
%template(VectorUInt32) vector<unsigned int>;
};
我在 C# 代码中得到以下结果:
public static void Foo(uint _x, uint _y, VectorUInt32 _results)
这很棒,但我真正希望的是:
public static void Foo(uint _x, uint _y, out VectorUInt32 _results)
有谁知道如何将 std::vector 从 C++ 映射到 C# 作为 ref 或 out 参数?
最佳答案
Stackoverflow 没有答案,真可耻!
无论如何,答案是,如果其他人有兴趣...如果您在 C# 中创建 VectorUInt32 类型并将其传递给 C++ 函数,它是通过引用传递的,因此可以在 C++ 中修改而无需 ref 或 out 参数.
界面变成:
C++
void Foo(unsigned int _x, unsigned int _y, std::vector< unsigned int > &_results)
接口(interface)文件
%include "std_vector.i"
namespace std {
%template(VectorUInt32) vector<unsigned int>;
};
C#
public static void Foo(uint _x, uint _y, VectorUInt32 _results)
用法
// Create and pass vector to C++
var vec = new VectorUInt32();
Foo(x, y, vec);
// do something with vec, its been operated on!
关于c# - 通过 ref/out 从 C# 到 C++ 的 Swig 传递 Std::vector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32206339/