go语言中,对于结构体,如果结构成员一样,但名字不一样,也认为是不同的结构。
package main
import "fmt"
type person struct {
name string
age int
}
type person2 struct {
name string
age int
}
func main() {
bb := make([]person, 1, 50)
bb[0].name = "xiaym"
bb[0].age = 35
//cc := bb[:]
aa := make([]person2, 1, 50)
aa = bb[:] // cannot use bb[:] (type []person) as type []person2 in assignment
fmt.Println(aa)
}
package main
import "fmt"
type person struct {
name string
age int
}
type person2 struct {
name string
age int
}
func main() {
bb := make([]person, 1, 50)
bb[0].name = "xiaym"
bb[0].age = 35
//cc := bb[:]
aa := make([]person2, 1, 50)
aa = bb[:] // cannot use bb[:] (type []person) as type []person2 in assignment
fmt.Println(aa)
}
有疑问加站长微信联系(非本文作者)