我正在尝试使用Go中的C++库。我对围棋也没什么经验。
我的C++方法如下所示:
std::vector<std::string> getAttribute(const std::string key);
我的文件中有这个:.swigcxx
%include "std_string.i"
%include "std_vector.i"
%include "MyCode.h"
%template(StringVector) std::vector<std::string>;
%{
#include "MyCode.h"
%}
但是Go不想让我访问它。我通过以下方式打印了一些信息:
attribs := ipuInfo.GetAttribute("foo")
fmt.Printf("%T\n", attribs)
fmt.Printf("%+v\n", attribs)
我得到:
bar.SwigcptrStringVector
<random number - address perhaps?>
但是我无法弄清楚如何获得矢量的单个内容。我试过了:
for index, val := range bar.GetAttribute("foo") {
}
但这给出了:
cannot range over bar.GetAttribute("foo") (type interface {})
我也尝试过调用它的方法,但它没有被声明(从 https://blog.nobugware.com/post/2020/c-bindings-in-go-and-swig/)。我也试过,它也不喜欢这样。.Capacity()attribs[0]
有人有什么建议吗?
非常感谢。
紫衣仙女
相关分类