package main
import (
"fmt"
)
type A struct {
ID int8
}
type B struct {
Arr [][]A
}
func main() {
b1 := B{
[][]A{
[]A{{1}},
},
}
b2 := B{
[][]A{
[]A{{2}, {3}},
},
}
bMerge := B{
append(b1.Arr, b2.Arr...),
}
fmt.Printf("For %#v, bMerge: %p; b1: %p\n", bMerge.Arr[0], &bMerge.Arr[0], &b1.Arr[0])
fmt.Printf("For %#11v, bMerge: %p; b1: %p\n", bMerge.Arr[0][0], &bMerge.Arr[0][0], &b1.Arr[0][0])
fmt.Printf("For %#11v, bMerge: %p; b2: %p\n", bMerge.Arr[1][0], &bMerge.Arr[1][0], &b2.Arr[0][0])
}
輸出結果
For []main.A{main.A{ID:1}}, bMerge: 0xc000060150; b1: 0xc00000c0a0
For main.A{ID: 1}, bMerge: 0xc00002c008; b1: 0xc00002c008
For main.A{ID: 2}, bMerge: 0xc00002c00a; b2: 0xc00002c00a
沒有留言:
張貼留言