LoginSignup
6
6

More than 5 years have passed since last update.

.\hoge.go:7: initialization loop

Posted at
hoge.go
package main

import "fmt"

var funcList = map[string]func(){
    "listing": listing,
}

func listing() {
    for key, _ := range funcList {
        fmt.Println(key)
    }
}

func main() {
    funcList["listing"]()
}
$ go run hoge.go
# command-line-arguments
.\hoge.go:7: initialization loop:
        C:\Users\…\GoSrc\tmp\hoge.go:7 funcList refers to
        C:\Users\…\GoSrc\tmp\hoge.go:9 listing refers to
        C:\Users\…\GoSrc\tmp\hoge.go:7 funcList

お、おう…

理由は分かる。宣言と定義を分けなくていいというのは楽なんだけど、こういう制限が発生するから、結局、利便性とのトレードオフだなぁ。

6
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6