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",n)
}


func main(){
	n := &Node{1}
	fmt.Printf("%p\n",n)
	n.SetAddition()
	fmt.Printf("%p\n",n)
}
  • 输出结构:
0xc0000100d0
0xc0000100d8
0xc0000100d0
posted @ 2020-04-06 17:38  Myuniverse  阅读(184)  评论(0编辑  收藏  举报