草庐IT

go - 如何在函数中传递指向结构的指针?

我想知道如何将*Type替换为?什么地址里面有结构?//mycode.gopackagemainimport"fmt"funcout(k*Type){fmt.Println(k)}funcmain(){typeDataIPstruct{Title,Descstring}Data:=DataIP{"Hello!","HelloGO!",}out(&Data)} 最佳答案 您需要在main()之外定义类型DataIP,该类型在包的范围内,而不仅仅是在main函数内:packagemainimport"fmt"typeDataIPstru