我正在尝试将向量变量放入 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/