Go:|Go: invalid operation - type *map[key]value does not support indexing

package mainimport "fmt"type Currency stringtype Amount struct { Currency Currency Value float32 }type Balance map[Currency]float32func (b *Balance) Add(amount Amount) *Balance { current, ok := (*b)[amount.Currency] if ok { (*b)[amount.Currency] = current + amount.Value } else { (*b)[amount.Currency] = amount.Value } return b }func main() { b := &Balance{Currency("USD"): 100.0} b = b.Add(Amount{Currency: Currency("USD"), Value: 5.0})fmt.Println("Balance: ", (*b)) }

【Go:|Go: invalid operation - type *map[key]value does not support indexing】
转载于:https://www.cnblogs.com/allenhaozi/p/8576228.html

    推荐阅读