【发布时间】:2013-10-20 20:39:42
【问题描述】:
我需要给这个结构添加切片类型。
type Example struct {
text []string
}
func main() {
var arr = []Example {
{{"a", "b", "c"}},
}
fmt.Println(arr)
}
然后我得到了
prog.go:11: missing type in composite literal
[process exited with non-zero status]
所以指定复合字面量
var arr = []Example {
{Example{"a", "b", "c"}},
但仍然出现此错误:
cannot use "a" (type string) as type []string in field value
http://play.golang.org/p/XKv1uhgUId
我该如何解决这个问题?如何构造包含数组(切片)类型的结构?
【问题讨论】:
标签: go