如何使用 Go 语言写出面向对象风格的代码
复制type Hero struct {
Name string
Age uint64
}
func NewHero() *Hero {
return &Hero{
Name: "盖伦",
Age: 18,
}
}
func (h *Hero) GetName() string {
return h.Name
}
func (h *Hero) GetAge() uint64 {
return h.Age
}
func main() {
h := NewHero()
print(h.GetName())
print(h.GetAge())
}
1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.
THE END