如何解决? https://play.golang.org/p/aOrqmDM91Jgo - golang编译错误:类型没有方法
:28: Cache.Segment undefined (type Cache has no method Segment)
:29: Cache.Segment undefined (type Cache has no method Segment)
package main
import "fmt"
type Slot struct {
Key []string
Val []string
}
type Cache struct{
Segment [3615]Slot
}
func NewCache(s int) *Cache{
num:=3615
Cacheobj:=new(Cache)
for i := 0; i < num; i++ {
Cacheobj.Segment[i].Key = make([]string, s)
Cacheobj.Segment[i].Val = make([]string, s)
}
return Cacheobj
}
func (*Cache)Set(k string, v string) {
for mi, mk := range Cache.Segment[0].Key {
fmt.Println(Cache.Segment[0].Val[mi])
}
}
func main() {
Cache1:=NewCache(100)
Cache1.Set("a01", "111111")
}
由于链接可以去随着时间的推移陈旧/变化,所以最好直接包含你的代码到您的帖子。 – Castaglia
感谢您的建议 – noname