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: , Sex: "男"}, Id: "", Grade: "三年级"}
fmt.Printf("%+v\n", s1) s2 := Student{Person{"张三", , "男"}, "", "三年级"}
fmt.Println(s2) s3 := Student{Person{Name: "张三", Age: , Sex: "男"}, Id: "", 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的更多相关文章

  1. golang 报错illegal rune literal

    记录一下,今天运行一端代码遇到这个报错"illegal rune literal",代码如下: func main() { http.HandleFunc('/login', lo ...

  2. Golang报错:Cannot convert expression of type interface{} to type []byte

    在使用golang实现后端登录逻辑的时候,碰到下面的问题:Cannot convert expression of type interface{} to type []byte 首先介绍下问题出现的 ...

  3. Django报错 The serializer field might be named incorrectly and not match any Got AttributeError when attempting to get a value for field `author_for` on serializer `KnownledgeBaseListSerializer`

    1.问题描述,在设置,model部分字段的serialier时,出现如下报错 字段如下: # 知识库List class KnownledgeBaseListSerializer(serializer ...

  4. 外显子分析报错解决方案bin field of BAM record does not equal value computed based on alignment start and end, and length of sequence to which read is aligned

    以下链接给出了解决方案:https://gatkforums.broadinstitute.org/gatk/discussion/4290/sam-bin-field-error-for-the-g ...

  5. 微信小程序 报错Setting data field "variableName" to undefined is invalid.

    Setting data field "variableName" to undefined is invalid. 将数据字段“variableName”设置为未定义是无效的. ...

  6. Django中search fields报错:related Field has invalid lookup: icontains

    models.py 文件 # coding:utf8from django.db import models class Book(models.Model):        name = model ...

  7. Django中pycharm中 报错 ---ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'system.sysuser', bu

    问题是:已经在settings.py文件中注册过app仍旧提示没有安装,并且使用makegirations命令时会抛出如下异常 解决方法: 找到自己的python3.x,进入site-packages ...

  8. Spring Cloud 使用 FeignClient 启动报错

    我们首先来看一下报错信息 Description: Field businessFeignClient in com.ysc.service.BusinessConfigService require ...

  9. 【ActiveMQ】消息生产者自动注入报错:Could not autowire. No beans of 'JmsMessagingTemplate' type found

    使用ActiveMQ过程中,定义消息生产者: package com.sxd.jms.producer; import org.springframework.beans.factory.annota ...

随机推荐

  1. sqlite 插入数据 too many variables

    相关文档:http://www.sqlite.org/limits.html#max_variable_number 一次插入条数限制500,参数最多999个.

  2. eclipse的debug模式经常自动跳到TheadPoolExecutor的断点

    1.问题:eclipse的debug模式经常自动跳到TheadPoolExecutor的断点,实在烦人 解决方法是: 在eclipse中选择Window->Preference->Java ...

  3. BZOJ 1426--收集邮票(概率与期望&DP)

    1426: 收集邮票 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 504  Solved: 417[Submit][Status][Discuss] ...

  4. Qt5学习笔记(控件)

    上面的程序仅仅可以显示一个 大概 的界面,对其进行单击等操作,界面仅有一些简单的反应,对应的程序不能得知界面有什么改变(是否进行单击选择,文本框中是否有文字输入) 下面对程序进行完善. T05Cont ...

  5. eclipse打包jar文件

    论文仿真做线性回归分类在人脸识别中应用与研究,在单机下实现LRC算法后,又在Hadoop云平台下实现了该算法.在比较实验结果时候需要放在相同硬件条件下比较.但是LRC单机算法是在windows下的ec ...

  6. 找到windows中的环境变量

    我的电脑,右击--->属性---->高级系统设置---->高级----->环境变量

  7. AssertJ断言系列-----------<数据库断言二>

    那么,在实际的接口测试中,我们除了要断言响应的数据正确之外,可能有的还需要断言数据层是否数据真的有入库. assertj db是可以直接对数据库进行断言和操作的. 一.创建一个students表 CR ...

  8. 架构师养成记--29.redis开篇

    主要有从下几点讲解 NOSQL(Redis) 简介.redis安装与部署 Redis基础事件类型详解 Redis高级命令 Redis与java的使用 Redis集群搭建 Redis集群与spring的 ...

  9. ltp-ddt eth过程中遇到的问题

    eth_iperf_tcp ETH_S_PERF_IPERF_TCP_INTPACING_8K_1448B source 'common.sh'; iface=`get_eth_iface_name. ...

  10. java获取某段时间内的月份列表

    /**获取两个时间节点之间的月份列表**/ private static List<String> getMonthBetween(String minDate, String maxDa ...