Can not assign to pair in a map

前端 未结 3 387
一生所求
一生所求 2020-12-21 00:16

I have the following pair defined in my go program

type pair struct {
  a float64
  b float64
}

Then I create a map:

dictio         


        
3条回答
  •  [愿得一人]
    2020-12-21 00:32

    That's not legal for reasons described here:

    Querying a map give a copy of the stored item, so there is no point assigning to it.

    The recommended workaround is:

    var xxoo = dictionary["xxoo"]
    xxoo.b = 5.0
    dictionary["xxoo"] = xxoo
    

提交回复
热议问题