我正在嘗試使用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]有人有什么建議嗎?非常感謝。
1 回答

紫衣仙女
TA貢獻1839條經驗 獲得超15個贊
這看起來像是函數重載的問題。我有2個具有相同名稱和不同參數的函數。當我重命名該方法,使其唯一且有效(盡管不這樣做)時。getAttribute
Capacity()
Get()
range
看起來Swig試圖生成包裝代碼來調用正確的方法,但無法處理不同的返回類型。
- 1 回答
- 0 關注
- 91 瀏覽
添加回答
舉報
0/150
提交
取消