goLand 运行报错 # command-line-arguments .\StudentGuanLi.go:8:28: undefined: student

goLand 运行报错

command-line-arguments

.\StudentGuanLi.go:8:28: undefined: student
goLand 运行报错 # command-line-arguments .\StudentGuanLi.go:8:28: undefined: student
编译器没有报错,但是运行时就找不到同包里定义的结构体
goLand 运行报错 # command-line-arguments .\StudentGuanLi.go:8:28: undefined: student

main方法运行go文件时默认只执行当前文件,如果本文件中调用了其他文件中的方法,需要在go run 时添加其他类。

goLand添加方法如下
goLand 运行报错 # command-line-arguments .\StudentGuanLi.go:8:28: undefined: student
goLand 运行报错 # command-line-arguments .\StudentGuanLi.go:8:28: undefined: student
goLand 运行报错 # command-line-arguments .\StudentGuanLi.go:8:28: undefined: student
文件就会被添加到这里
goLand 运行报错 # command-line-arguments .\StudentGuanLi.go:8:28: undefined: student
然后再执行就不会报找不到的异常了
goLand 运行报错 # command-line-arguments .\StudentGuanLi.go:8:28: undefined: student