美文网首页
go map的使用

go map的使用

作者: 失眠是真滴难受 | 来源:发表于2020-04-12 01:12 被阅读0次

    tmp := map[key]value
    上面是创建一个 map 的格式,其中 key 必须为可比较的类型,包括:boolean、numeric、string、pointer、channer、interface。而 value 可以为任意类型,包括 struct

    tmp := map[int]*Process{
        1: &Process{
            value: 0;
        },
        2:.......
    }
    

    直接用 struct 创建的 map 没法对 struct 内部的变量赋值。map 实际上保存的是地址,strunt 也是一个地址,所以要对 struct 里的 map 赋值,就需要指向指针的指针。

    相关文章

      网友评论

          本文标题:go map的使用

          本文链接:https://www.haomeiwen.com/subject/voummhtx.html