Here is the explation of const from the go programmer lauguage specification A constant declaration binds a list of identifiers (the names of the constants) to the values of a list of constant expressions <https://golang.org/ref/spec#Constant_expressions>.
在 2017年9月8日星期五 UTC+8下午12:52:44,DrGo写道: > > Sorry if this was asked before, but I could not find any relevant posts. > > Any reason why this struct literal (made up of fields that can be declared > const) is not allowed? > > const UnknownPos = scanner.Position{"", -1, -1, -1} > > error: const initializer scanner.Position literal is not a constant. > > Currently, I declare it as a variable, so that I can do things like > if pos == UnknownPos { > ... > } > > Cheers, > > > > > > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.