構造体 (GO 言語) でのスライスの開始に苦労しています。これは簡単かもしれませんが、それでも解決できません。以下のエラーが発生します
./prog.go:11:1: syntax error: unexpected var, expecting field name or embedded type
./prog.go:25:2: no new variables on left side of :=
./prog.go:26:2: non-name g.s on left side of :=
構造体の一部として宣言するs
必要があると思うので、なぜそのエラーが発生するのだろうか。誰かがアドバイスを得た?
package main
import "fmt"
type node struct {
value int
}
type graph struct {
nodes, edges int
s []int
}
func main() {
g := graphCreate()
}
func input(tname string) (number int) {
fmt.Println("input a number of " + tname)
fmt.Scan(&number)
return
}
func graphCreate() (g graph) {
g := graph{input("nodes"), input("edges")}
g.s = make([]int, 100)
return
}