在我的目录中,/go/src/lodo我有两个文件,main.go和uniqueElement.
uniqueElement.go
package main
import "fmt"
func unique(a []int) {
var value int
for i:= range a {
value = value ^ a[i]
}
fmt.Println(value)
}
Run Code Online (Sandbox Code Playgroud)
main.go
package main
func main() {
var a = []int{1, 4, 2, 1, 3, 4, 2}
unique(a[0:])
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误
./main.go:7: undefined: unique
Run Code Online (Sandbox Code Playgroud)
我怎样才能正确地调用独特的main?
您可能go run main.go只使用编译运行代码并运行main.go尝试运行go run main.go uniqueElement.go或构建并运行生成的二进制文件