Dereferencing a map index in Golang

前端 未结 3 884
渐次进展
渐次进展 2020-12-03 11:27

I\'m learning Go currently and I made this simple and crude inventory program just to tinker with structs and methods to understand how they work. In the driver file I try t

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 12:15

    While the other answers are useful, I think in this case it is best just to make non-mutating functions not take a pointer:

    func (i item) GetName() string{
        return i.itemName
    }
    
    func (i item) GetAmount() int{
        return i.amount
    }
    

提交回复
热议问题