type DataNode struct{
cmd *string
desc *string
handler func() int
next *DataNode
}
var head = []DataNode{
{cmd:"help", desc:"cmd tips", handler:help, next:&head[1]},
{cmd:"add", desc:"addition of two numbers", handler:add, next:nil}}
func main(){
//head[0].next = &head[1]
//head[1].next = &head[2]
//head[2].next = nil
......
}
如果在main中初始化next,则报错如下:
.\menu2.go:18:initialization loop:
E:\Go_WorkSpace\lab3\main\menu2.go:18 head refers to
E:\Go_WorkSpace\lab3\main\menu2.go:18 help refers to
E:\Go_WorkSpace\lab3\main\menu2.go:18 head
如果在{}中初始化next,出错如下:
.\menu2.go:18:typechecking loop involving head = []DataNode literal
E:\Go_WorkSpace\lab3\main\menu2.go:18 head
E:\Go_WorkSpace\lab3\main\menu2.go:18 head[1]
E:\Go_WorkSpace\lab3\main\menu2.go:18 &head[1]
E:\Go_WorkSpace\lab3\main\menu2.go:18 composite literal
E:\Go_WorkSpace\lab3\main\menu2.go:18 []DataNode literal
第二种错误可能如6楼所说,go语言在我这种方式构造的时候参数值必须是基本类型,要是自定的Struts是不能这样直接在构造里面写的,但是我在main中定义有会报第一种错误。
请各位Go友帮忙解决下这个问题~~~
有疑问加站长微信联系(非本文作者)