Go基础_1_49 结构体别名
Tutorial: Go初级
Category: Go
Published: 2026-04-07 13:58:26
Views: 21
Likes: 0
Comments: 0
package main
import "fmt"
type Person struct {
name string
}
func (p Person) show() {
fmt.Println("Person--->", p.name)
}
type People = Person
func (p People) show2() {
fmt.Println("People--->", p.name)
}
type Student struct {
Person
People
}
func main() {
var s Student
s.Person.name = "王二狗"
s.Person.show()
fmt.Printf("%T,%T\n", s.Person, s.People)
s.People.name = "李小花"
s.People.show2()
s.Person.show()
}