#青训营 x 字节后端训练营# ##### Golang中的结构体方法
类似于C++中结构体函数,使其变成了一个类成员函数。
~~~go
package main
import "fmt"
type user struct {
name string
password string
}
func (u user) checkPassword(u user, password string) bool{
return u.password == password
}//密码验证
func (u *user) resetPassword(password string) bool{
u.password = password
}//密码修改
func main () {
a := {"wang", "1024"}
a.resetPassword("2048") //
fmt.Println(a.checkPassword("2048")) //true
}
~~~