标签:str UNC gen main test pack 就是 printf 字母
//方法:函数指定接收者之后就是方法,只有某个具体的类型才能调用
package main
import "fmt"
type people struct {
name string
gender string
}
//go中,约定使用类型首字母小写
func (p people) dream() {
fmt.Printf("name :%s", p.name)
}
func main() {
var test = people{
name: "test",
gender: "nan",
}
test.dream()
}
//使用指针修改内容
func (p *people) dream() {
p.name = "test2"
fmt.Printf("name :%s", p.name)
}
func main() {
var test = &people{
? name: "test",
? gender: "nan",
}
test.dream()
}
标签:str UNC gen main test pack 就是 printf 字母
原文地址:https://www.cnblogs.com/kylingx/p/13290144.html