繁体   English   中英

Swig通过ref将Std :: vector通过ref /从C#传递到C ++

[英]Swig Pass Std::vector by ref / out from C# to C++

给定C ++函数

void Foo(unsigned int _x, unsigned int _y, std::vector< unsigned int > &_results)

和Swig接口文件来映射std :: vector以在C#中键入VectorUInt32

%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)

接口文件

%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!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM