Foundation of Go Language —— 11. structure & function (Not translated)
»
    Go语言中没有class、只有结构体,但是struct可以通过指定函数接收器的方法绑定特定的方法:
    import (
        "time"
    )
    type People struct {
        Name string//首字母大写表示包外部能够使用,首字母小写则只能在包内访问
        Birthday time.Time
    }
    func (p *People) setName(name string) {//注意:此处只能使用指针类型,否则没法绑定结构体的内存地址
        p.Name = name
    }
    p.setName("Go language") //注意:此处只能使用指针类型,否则没法绑定结构体的内存地址
    
    ————www.v-signon.com学习者共勉
                        
«
--Alex.Zhang
--www.v-signon.com Learningers Co-Encouraged
Back
Personal Art: www.up-task.com Unit: Individual
中文 Русский 京ICP备19038994号-2
If the content on this website infringes upon your any rights, please contact me at 1307776259@qq.com for removal