package main
import (
"fmt"
)
type N struct {
Name string `json:"name"`
Age int `json:"age"`
B *BBB `json:"b"`
}
type BBB struct {
yy string
bb byte
}
func (n N) Haddname(b *BBB) {
n.B.yy=b.yy
}
func main(){
n:=N{
Name: "test",
Age: 100,
B: &BBB{yy: "9999999",bb:0},
}
n.Haddname(&BBB{yy: "000000"}) //yy值被修改
nn:=N{
Name: "dfs",
Age: 200,
B: &BBB{yy: "fsdf",bb:0},
}
fmt.Println(n.B.yy,nn.B.yy)
}
输出
000000 fsdf
进程 已完成,退出代码为 0