Golang中无法通过(:=)给结构体切片数据类型赋值的问题
Golang中无法通过(:=)给结构体切片数据类型赋值的问题
package main
import "fmt"
type Hospital struct {
name1 string
phone int
}
type Doctors struct {
Hospital
id int
name string
patients []string
}
func main() {
doc := Doctors{}
var
doc.name1 = "Govt"
doc.phone = 123456
doc.id = 11
doc.name = "tinq"
doc.patients :=[]string{"Jone","David"}
How to assingn a value for patients field?
Getting this error:
./prog.go:24:2: non-name doc.patients on left side of :=
如何为 patients 字段赋值?
出现此错误: ./prog.go:24:2: := 左侧的 doc.patients 不是名称
更多关于Golang中无法通过(:=)给结构体切片数据类型赋值的问题的实战教程也可以访问 https://www.itying.com/category-94-b0.html
3 回复
您应该在提到的地方使用 = 而不是 :=。
同时,请使用正确的代码块格式,可以通过缩进或代码围栏来实现。
或者,您也可以选中代码,然后点击工具栏中的 </> 图标。


