package main
import "fmt"
type TestFunc func(*Bar, string)
type Bar struct {
Name string
Alias string
}
func (t *Bar) SetName(name string) {
t.Name = name
fmt.Println("Name:", t.Name)
}
func (t *Bar) SetAlias(alias string) {
t.Alias = alias
fmt.Println("Alias:", t.Alias)
}
type Foo struct {
f TestFunc
}
func main() {
foo := new(Foo)
bar := new(Bar)
foo.f = (*Bar).SetName
foo.f(bar, "LeBron Raymone James")
foo.f = (*Bar).SetAlias
foo.f(bar, "King")
}
go语言 记录奇怪的写法--慢慢品味
最新推荐文章于 2022-12-24 13:46:34 发布