Created
June 25, 2017 14:57
-
-
Save YanhaoYang/a2297f271b8933a8a71154f78b49b42f to your computer and use it in GitHub Desktop.
golang-struct-copy-is-memory-copy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type A struct { | |
S1 string | |
} | |
type B struct { | |
Apt *A | |
S2 string | |
} | |
func main() { | |
b1 := B{Apt: &A{S1: "hi"}, S2: "h2"} | |
b2 := b1 | |
b2.Apt.S1 = "haha" | |
b2.S2 = "ha2" | |
fmt.Println(b1, b2, b1.Apt, b2.Apt) | |
} | |
// https://play.golang.org/p/UhdzGKz-s0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment