我在定义数组的地方有以下示例代码,但无法编译:
$ cat a.go
package f
func t() []int {
arr := [] int {
1,
2
}
return arr
}
oreyes@OREYES-WIN7 ~/code/go
$ go build a.go
# command-line-arguments
.\a.go:5: syntax error: unexpected semicolon or newline, expecting }
.\a.go:7: non-declaration statement outside function body
.\a.go:8: syntax error: unexpected }
但是,如果我删除换行符,它将起作用:
$ cat a.go
package f
func t() []int {
arr := [] int {
1,
2 }
return arr
}
oreyes@OREYES-WIN7 ~/code/go
$ go build a.go
怎么来的?
慕的地6264312
相关分类