自己学习的,下面代码m转到p出错了,m2却可以。。这语言有点难
package main
import "fmt"
type People interface {
say()
}
type Men struct {
name string
}
func (men *Men) say() {
fmt.Println("mem say hi:", men.name);
}
func main() {
m := Men{"mike"}
m.say()
m2 := new(Men)
m2.name = "new men"
var p People
p = m2
p = m //error cannot use m (type Men) as type People in assignment:
p.say()
}
https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/11.1.md
这个实例能完全解决你的问题
#5
更多评论