download1002 2017-06-12 14:16
浏览 495
已采纳

使用Go语言创建列表列表

Hi I try to create slice of slice of SyntaxCommand with undetermine length

var result = make([][]SyntaxCommand)
result = append(result, []SyntaxCommand{})
temp := SyntaxCommand{}
result = append(result[len(result)-1], temp)

but i encounter error

missing len argument to make([][]SyntaxCommand)
temp = SyntaxCommand{}

How to easily make a list of list of object that is nullable? Then add new list to the end, and an object to the last list with non undetermined length?

  • 写回答

1条回答 默认 最新

  • doutan8601 2017-06-12 14:20
    关注

    If you don't want to initialize the slice, don't use make

    var result [][]SyntaxCommand
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?