如何使用 Go 语言写出面向对象风格的代码

  发布时间:2025-11-05 12:41:38   作者:玩站小弟   我要评论
复制typeHerostruct{ Namestring Ageuint64 } funcNewHero()*H 。
如何使用 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.
  • Tag:

相关文章

最新评论