我是靠谱客的博主 从容白羊,这篇文章主要介绍map赋值前要先初始化:assignment to entry in nil map,现在分享给大家,希望可以做个参考。

注意这种map的嵌套的形式,make只初始化了map[string]T部分(T为map[int]int),所以下面的赋值会出现错误:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
test := make(map[string]map[int]int) test["go"][0] = 0 // error 1 2 正确的做法: test := make(map[string]map[int]int) test["go"] = make(map[int]int) test["go"][0] = 0 1 2 3 一个常用的做法: test := make(map[string]map[int]int) if test["go"] = nil { test["go"] = make(map[int]int) } test["go"][0] = 0
原文:https://blog.csdn.net/jason_cuijiahui/article/details/79410471

转载于:https://www.cnblogs.com/nyist-xsk/p/9969922.html

最后

以上就是从容白羊最近收集整理的关于map赋值前要先初始化:assignment to entry in nil map的全部内容,更多相关map赋值前要先初始化:assignment内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部