美文网首页
《go语言实战》总结

《go语言实战》总结

作者: 包牙齿 | 来源:发表于2018-07-31 17:01 被阅读16次

    方法集

    method receivers Values
    (t T) T and *T
    (t *T) *T
    Values method receivers
    T (t T)
    *T (t T) and (t *T)
    package main
    
    import "fmt"
    
    type User struct {
        name string
        age  int
    }
    
    func main() {
        user := User{name: "dick", age: 18}
        uP := &User{name: "dick", age: 18}
        receiver(user)
        receiver(*uP)
        fmt.Println("============")
        receiverPoint(uP)
    
    }
    
    func receiver(user User) {
        fmt.Println("receiver name:", user.name, " age:", user.age)
    }
    
    func receiverPoint(user *User) {
        fmt.Println("receiverPoint name:", user.name, " age:", user.age)
    }
    
    

    相关文章

      网友评论

          本文标题:《go语言实战》总结

          本文链接:https://www.haomeiwen.com/subject/huvhvftx.html