标签:str main pre imp ntp poi 转换 自动 value
package main
import "fmt"
type Person struct {
//和变量定义不同,不要写var关键字
Id int
Name string
Sex byte
}
type Student struct {
Person
Hobby string
}
func (s Person) PrintValue() {
fmt.Println("该方法receiver is person")
}
func (s *Person) Printpointer() {
s.Name = "st"
fmt.Println("该方法receiver is *person")
}
func main() {
s1 := Student{Person{1, "steven", ‘m‘}, "running"}
s1.PrintValue() //继承person的方法
s1.Printpointer()//自动转换类型
var s2 *Student
s2 = new(Student)
s2.Printpointer()
fmt.Println(s2.Name)//st
}
标签:str main pre imp ntp poi 转换 自动 value
原文地址:https://www.cnblogs.com/zhaopp/p/11565398.html