Golang报错mixture of field:value and value initializers

Posted xbblogs

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Golang报错mixture of field:value and value initializers相关的知识,希望对你有一定的参考价值。

Golang 在使用匿名成员初始化时,如果出现

mixture of field:value and value initializers

是因为初始化的方式不对,见代码:
package main

import (
    "fmt"
)

type Person struct {
    Name string
    Age  int
    Sex  string
}

type Student struct {
    Person
    Id    string
    Grade string
}


func main() {
    s1 := Student{Person: Person{Name: "张三", Age: 13, Sex: ""}, Id: "13321", Grade: "三年级"}
    fmt.Printf("%+v
", s1)

    s2 := Student{Person{"张三", 13, ""}, "12312", "三年级"}
    fmt.Println(s2)

    s3 := Student{Person{Name: "张三", Age: 13, Sex: ""}, Id: "13321", Grade: "三年级"} //报错 mixture of field:value and value initializers(字段的混合:值和值初始化器)
    fmt.Println(s3)
}

s3直接导致代码编译不过去,想要指定字段就必须按 s1的方式 Person:Person{xxx:"xxx"},要么就不指定按照s2的方式

 



以上是关于Golang报错mixture of field:value and value initializers的主要内容,如果未能解决你的问题,请参考以下文章

混合高斯模型(Mixtures of Gaussians)

PP: Deep clustering based on a mixture of autoencoders

推荐系统(十五)多任务学习:谷歌MMoE(Multi-gate Mixture-of-Experts )

推荐系统(十五)多任务学习:谷歌MMoE(Multi-gate Mixture-of-Experts )

推荐系统(十五)多任务学习:谷歌MMoE(Multi-gate Mixture-of-Experts )

Multi-gate Mixture-of-Experts(MMoE)