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

Posted hao.ma

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Go: invalid operation - type *map[key]value does not support indexing相关的知识,希望对你有一定的参考价值。

package main

import "fmt"

type Currency string

type Amount struct {
    Currency Currency
    Value float32
}

type Balance map[Currency]float32

func (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: invalid operation - type *map[key]value does not support indexing的主要内容,如果未能解决你的问题,请参考以下文章

我的OpenGL学习进阶之旅解决OpenGL在使用glUniform系列api时出现了 GL_INVALID_OPERATION 1282错误

我的OpenGL学习进阶之旅解决OpenGL在使用glUniform系列api时出现了 GL_INVALID_OPERATION 1282错误

glVertexAttribPointer 返回 GL_INVALID_OPERATION

glReadPixels 函数返回错误 1282 (GL_INVALID_OPERATION)

glVertexAttribPointer 提高 GL_INVALID_OPERATION

wglCreateContext 抛出 INVALID_OPERATION 异常