go - 如何在 Go 中将向量放入结构中?

标签 go vector

我正在尝试将向量变量放入 Google 的 Go 编程语言的结构中。这是我目前所拥有的:

想要:

type Point struct { x, y int }
type myStruct struct {
 myVectorInsideStruct vector;
}

func main(){
 myMyStruct := myStruct{vector.New(0)};
 myPoint := Point{2,3};
 myMyStruct.myVectorInsideStruct.Push(myPoint);
}

有:

type Point struct { x, y int }

func main(){
myVector := vector.New(0);
myPoint := Point{2,3};
myVector.Push(myPoint);
}

我可以让向量在我的主函数中正常工作,但我想将它封装在一个结构中以便于使用。

最佳答案

我不确定这是否是你想要的,所以如果它不起作用请发表评论:

package main

import "container/vector";

type Point struct { x, y int };

type mystruct struct {
    myVectorInsideStruct * vector.Vector;
}

func main() {
    var myMyStruct mystruct;
    myMyStruct.myVectorInsideStruct = new(vector.Vector);
    myPoint := Point{2,3};
    myMyStruct.myVectorInsideStruct.Push(myPoint);
}

关于go - 如何在 Go 中将向量放入结构中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1781028/

相关文章:

go - 为什么安装dlv失败

go - 将未知大小的 io.Reader 读入 golang 中的字节数组

arrays - 在 golang 中创建 map 数组的 map

c++ - 标准 vector C++——深拷贝或浅拷贝

r - 连接数据框的行

regex - 在括号外用逗号标记

go - 如何处理 Response JSON 有没有键的自定义字段?

recursion - Clojure,对向量列表求和,沿途记录位置

c++ - 获取使用 vector 的 cygwin_exception::open_stackdumpfile

c++ - 是否可以从 shared_ptr 的 vector 中删除元素?