编译器错误将切片附加到切片 [英] Compiler error appending slice to slice
本文介绍了编译器错误将切片附加到切片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Go编译器抱怨我的代码将切片附加到切片.以下是相关摘录:
The Go compiler is complaining about my code to append a slice to a slice. Here are relevant excerpts:
type LanidEntry struct {
lanid string
group string
contact string
}
var lanids []LanidEntry
func load_file() (lanids_loaded []LanidEntry, errormsgs string) {
// ...
}
func Load() (lanids []LanidEntry, errormessages string) {
lanids_loaded, errormsgs := load_file(filename1, contact1)
lanids = append(lanids, lanids_loaded)
// ...
}
append
行生成此编译器消息:
The append
line generates this compiler message:
src\load_lanids\load_lanids.go:50: cannot use lanids_loaded (type []LanidEntry) as type LanidEntry in append
根据一个Go Blog帖子 在附加:内置功能部分下.
推荐答案
您需要使用...
:
lanids = append(lanids, lanids_loaded...)
也请格式化您的代码:)
Also, also please format your code :)
您还应该在Wiki上阅读切片技巧.
You should also read Slice Tricks on the Wiki.
这篇关于编译器错误将切片附加到切片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文