获取不到map中struct对象的指针

__Golang__ · 2020-11-06 21:40:20 · 1080 次点击

go101不错,就是读起来像翻译的外文

#5
更多评论

这是因为stus["a"]的返回值不是固定的地址, 算不出来吧, 因为每次都要复制一次. 你如果把stus["a"]赋值给一个栈变量就可以了.

s := stus["a"]
    //p := stus["a"]      //cannot take the address of stus["a"]
    p := &s // 这样就不会报错了
#1