抱歉这个基本问题。我是 GoLang 的新手。
我有一个名为的自定义类型ProtectedCustomType,我不希望其中的变量set直接由调用者使用,而是希望一个Getter/Setter方法来执行此操作
下面是我的ProtectedCustomType
package custom
type ProtectedCustomType struct {
name string
age int
phoneNumber int
}
func SetAge (pct *ProtectedCustomType, age int) {
pct.age=age
}
这是我的main功能
import (
"fmt"
"./custom"
)
var print =fmt.Println
func structCheck2() {
pct := ProtectedCustomType{}
custom.SetAge(pct,23)
print (pct.Name)
}
func main() {
//structCheck()
structCheck2()
}
但是我无法继续进行.. 你能帮我看看如何在 GoLang 中实现 getter-setter 概念吗?
慕斯王
相关分类