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
推荐阅读
- 多线程NSOperation
- 解决SyntaxError:|解决SyntaxError: invalid syntax
- typeScript入门基础介绍
- 带你了解类型系统以及flow和typescript的基本使用
- 由Uncaught|由Uncaught TypeError: this.player.startMoveAt is not a function引申
- swift类型别名(typealias)
- mac升级之(xcrun:|mac升级之:xcrun: error: invalid active developer path, missing xcrun)
- Python|Python TypeError: 'module' object is not callable 原因分析
- QQ??|QQ?? ?????? ????
- react+typescript+router框架搭建笔记