请教为啥无法获取stus["a"]
的指针
type Student struct {
Name string
}
func main() {
stus := make(map[string]Student)
stus["a"] = Student{"a"}
p := &stus["a"] //cannot take the address of stus["a"]
}
有疑问加站长微信联系(非本文作者)

请教为啥无法获取stus["a"]
的指针
type Student struct {
Name string
}
func main() {
stus := make(map[string]Student)
stus["a"] = Student{"a"}
p := &stus["a"] //cannot take the address of stus["a"]
}
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
`单行代码`
这是因为stus["a"]的返回值不是固定的地址, 算不出来吧, 因为每次都要复制一次. 你如果把stus["a"]赋值给一个栈变量就可以了.
谢谢大佬
详细请看 Go101的问答 - 为什么映射元素不可被取地址?
@avtion 谢谢:)
go101不错,就是读起来像翻译的外文
应该就是
每一个字都看得懂,连起来就不懂了