GOLANG学习25. 结构体方法
package main
import (
"fmt"
)
//定义类型别名
type integer int
func (p integer) print() {
fmt.Println("this is p:", p)
}
func (p *integer) set(b integer) {
*p = b
}
//定义结构体
type Student struct {
Name string
Age int
Score float32
sex int
}
/**
定义结构体的初始化
*/
func (p *Student) init(name string, age int, score float32, sex int) {
p.Name = name
p.Age = age
p.Score = score
p.sex = sex
}
//获取
func (p Student) get() Student {
return p
}
func main() {
var stu Student
stu.init("张珊", 20, 99.9, 1) //标准(&stu).init("张珊", 20, 99.9, 1)
stu1 := stu.get()
fmt.Println(stu1)
var a integer
a.set(1000)
a.print()
}