相关疑难解决方法(0)

如何声明一个新的结构实例与"var"不同于在Go中使用"new"?

以下代码创建了一个可用的struct实例Car.这与使用有new(Car)什么不同?

例:

type Car struct {
  make string
}

func Main() {
  var car Car; // how is this different than "car := new(Car)"?

  car.make = "Honda"
}
Run Code Online (Sandbox Code Playgroud)

go

3
推荐指数
1
解决办法
293
查看次数

标签 统计

go ×1