我需要将映射发送到在导入包中声明的函数,并不断收到此错误:
./main.go:21: 不能在函数参数中使用 m (type map[string]ticket) 作为类型 map[string]some_package.ticket
这是 golang GOPATH 文件夹中 main.go 的代码:
package main
import (
"time"
sp "./some_package"
)
type ticket struct {
Timestamp int64
Identification_number int
}
var m map[string]ticket
func main() {
humans := 10
m = make(map[string]ticket)
m["ticket1"] = ticket{time.Now().Unix(), 1234}
sp_ := sp.New(humans)
sp_.SetTicket(m)
}
这是 golang GOPATH 文件夹中 /some_package 中 some_package.go 的代码:
package some_package
type park struct{
card map[string]ticket
people int
}
type ticket struct {
Timestamp int64
Identification_number int
}
func (p *park) SetTicket(m map[string]ticket)(){
}
func New(humans int)(p *park){
p.card = make(map[string]ticket)
p.people = humans
return p
}
我应该如何将映射的值传递给导入的包函数或从父包获取函数内部的映射值?这甚至可能还是有解决方法?
慕村225694
相关分类