Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
golang对象上的设置值_Go - Fatal编程技术网

golang对象上的设置值

golang对象上的设置值,go,Go,我有以下代码: 类型TestStruct struct{ 值int } func(t TestStruct)SetValue(v int){ t、 值=v } func(t TestStruct)GetValue()int{ 返回t值 } func TestTesting(t*testing.t){ s:=TestStruct{} s、 设定值(4) fmt.Println(s.GetValue()) } 为什么它打印0而不是4 为什么setter不更改测试有权访问的结构上的实例?为sette

我有以下代码:

类型TestStruct struct{
值int
}
func(t TestStruct)SetValue(v int){
t、 值=v
}
func(t TestStruct)GetValue()int{
返回t值
}
func TestTesting(t*testing.t){
s:=TestStruct{}
s、 设定值(4)
fmt.Println(s.GetValue())
}
为什么它打印0而不是4


为什么setter不更改测试有权访问的结构上的实例?

为setter使用指针接收器:
func(t*TestStruct)SetValue(v int){}