package main import "fmt" type User struct{ ID int name string } func (user *User) getName() string { return user.name } func main() { user1 := User{1,"abc"} user2 := &user1 user2.name="kk" fmt.Println(user1.getName(),user2.getName()) }
package main import "fmt" type User struct{ ID int name string } func (user *User) getName() string { return user.name } func main() { user1 := User{1,"abc"} user2 := &user1 user2.name="kk" fmt.Println(user1.getName(),user2.getName()) }
转载于:https://www.cnblogs.com/xmxkkk/p/3819508.html