81_Go基础_1_49 结构体别名

 1 package main
 2 
 3 import "fmt"
 4 
 5 type Person struct {
 6     name string
 7 }
 8 
 9 func (p Person) show() {
10     fmt.Println("Person--->", p.name)
11 }
12 
13 // 类型别名
14 type People = Person
15 
16 func (p People) show2() {
17     fmt.Println("People--->", p.name)
18 }
19 
20 type Student struct {
21     //嵌入两个结构体
22     Person
23     People
24 }
25 
26 func main() {
27     var s Student         //s.name = "王二狗" //ambiguous selector s.name
28     s.Person.name = "王二狗" //s.show() //ambiguous selector s.show
29     s.Person.show()       // Person---> 王二狗
30 
31     fmt.Printf("%T,%T\n", s.Person, s.People) //main.Person,main.Person
32 
33     s.People.name = "李小花"
34     s.People.show2() // People---> 李小花
35     s.Person.show()  // Person---> 王二狗
36 }

 

上一篇:用c# 个人研究二进制读写规则(一)


下一篇:Linux TC (Traffic Control 流控工具)