1、继承后增加新字段

type Car struct {
    weight int
    name   string
}
type Bike struct {
    Car
    lunzi int
}

不过有个问题是vscode在使用Bike实例对象时,代码自动完成功能会显示一个Car,强迫症不能忍。
2、如果不增加新字段,可以直接

type Bike Car

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2021-12-08
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
猜你喜欢
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2021-12-15
  • 2022-12-23
相关资源
相似解决方案