package main
import (
"fmt"
)
type Medal struct {
Name string
Obtainable bool
}
type Technician struct {
Name string
}
func (t *Technician) CheckMedalAvailability(medal *Medal) {
if medal.Obtainable {
fmt.Printf("搞技术真的能获得 %s 勋章,大家能满足吗?\n", medal.Name)
} else {
fmt.Printf("搞技术不能获得 %s 勋章,大家可能不太满足。\n", medal.Name)
}
}
func main() {
goldMedal := Medal{Name: "黄金勋章", Obtainable: true}
tech := Technician{Name: "张三"}
tech.CheckMedalAvailability(&goldMedal)
}
你要new 一个Technician 实例化,而不是直接这样调用。
tech := Technician{Name: "张三"}