且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

GoLang中的二传手

更新时间:2023-11-23 08:38:28

如果要使用setter,则应使用方法声明:

If you want to have setter you should use method declaration:

func(pct *ProtectedCustomType) SetAge (age int)  {
    pct.age = age
}

然后您将可以使用:

pct.SetAge(23)

这种声明使您可以在结构上执行功能,通过使用

This kind of declarations enables you to execute function on your structure, by using

(pct * ProtectedCustomType)

您正在传递指向您的结构的指针,因此对它的操作会更改其内部表示形式.

Your are passing pointer to your struct so operations on it changes its internal representation.

您可以在此链接,或在官方文档下.