Gitart
10/30/2016 - 10:05 AM

Copy structures

Copy structures

package main

import "fmt"

type T struct {
	Id   int
	Name string
}

func Copy(a *T, b *T) {
	*a = *b
}

func main() {
	var a = &T{1, "one"}
	var b = &T{2, "two"}

	fmt.Println(a, b)

	Copy(a, b)
	fmt.Println(a, b)

	a.Id = 7
	fmt.Println(a, b)
}