复制结构体(创建一份拷贝)
package main
import "fmt"
type T struct {
I int
S string
}
func main() {
// initialize a struct
t := T{1, "one"}
// make struct copy
u := t // u has its field values equal to t
if u == t { // true
fmt.Println("u and t are equal") // Prints: "u and t are equal"
fmt.Printf("u address is: %p\nt address is:%p\n", &u, &t)
}
}
最后更新于