Go中函数接收器不能改变接收者的地址

注意:Go中函数接收器不能改变接收者的地址

package main

import(
	"fmt"
)

// Node 节点
type Node struct {
	data int
}

// SetAddition 设置n的地址 看能不能改变n的地址
func(n *Node)SetAddition(){
	n1 := &Node{3}
	n = n1
	fmt.Printf("%p
",n)
}


func main(){
	n := &Node{1}
	fmt.Printf("%p
",n)
	n.SetAddition()
	fmt.Printf("%p
",n)
}
  • 输出结构:
0xc0000100d0
0xc0000100d8
0xc0000100d0
原文地址:https://www.cnblogs.com/MyUniverse/p/12643112.html