map[key] 可以获取到value的引用,但是这个引用如何记录呢?
比如我的value有100个成员变量
map[key].value1 = a
map[key].value2 = b
map[key].value3 = c
... 这样写下去不是要有100次检索的过程么.这不科学啊.
point := &map[key]
point .value1 = a
point .value2 = b
point .value3 = c
... 这样写不是更科学么.但是编译器提示我不支持&.请问我该怎么作呢?
有疑问加站长微信联系(非本文作者)

value 使用指针,使用值的话拿到的都是值的拷贝
指针是可以但是总是感觉不够优雅。
value使用指针,如果直接用
point.value1=a
这样赋值的话,会panic吧,空指针呀如果value不用指针
stus := map[string]Student{}
不能使用stus["stu001"].Name1 = "a"
直接赋值,编辑就会报错cannot assign to struct field stus["stu001"].Name1 in map
而
stus := &map[string]Student{}
更是不对,因为这个时候 stus是一个指针类型*map[string]Student
不支持indexing,编译会报type *map[string]Student does not support indexing
正确为使用为
或者
https://cloud.tencent.com/developer/doc/1101这里面有map章节中文的内容,楼主可以看看对你有没有用~