我想在我的围棋程序中列举行星。每个行星都有一个通用名称(例如:“金星”)和以天文单位表示的与太阳的距离(例如:0.722)
所以我写了这段代码:
type planet struct {
commonName string
distanceFromTheSunInAU float64
}
const(
venus planet = planet{"Venus", 0.387} // This is line 11
mercury planet = planet{"Mercury", 0.722}
earth planet = planet{"Eath", 1.0}
mars planet = planet{"Mars", 1.52}
...
)
但是 Go 不允许我编译它,并给了我这个错误:
# command-line-arguments
./Planets.go:11: const initializer planet literal is not a constant
./Planets.go:12: const initializer planet literal is not a constant
./Planets.go:13: const initializer planet literal is not a constant
./Planets.go:14: const initializer planet literal is not a constant
你知道我该怎么做吗?谢谢
潇湘沐
相关分类