Read a blog about copying structs in GO. I don’t notice the same behavior in my tests. What am I missing ?

Written by
reddit
Link to Post

https://www.reddit.com/r/golang/comments/bnh355/read_a_blog_about_copying_structs_in_go_i_dont/ by 

I don’t observe the copy-linking behaviour for structs containing complex types. The blog post is at this link https://flaviocopes.com/go-copying-structs/ What I am missing ?

I run a test here https://play.golang.org/p/Exk1Rb6BEBR and with the testing framework.

func TestCopy(t *testing.T) { pod := Pod{position: Dot{10280, 2663}, vx: 434, vy: 41, angle: 46, hasShieldOn: false, nextCpID: 2, radius: 400.0} newPod := pod pod.position = Dot{0, 0} if newPod.position.x == pod.position.x || newPod.position.y == pod.position.y { t.Errorf("positions have been changed even if different variables") } 

}

submitted by /u/Poutrator
[link] [comments]

Article Tags:
· ·
Article Categories:
reddit

Leave a Reply