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: , 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的更多相关文章
- golang 报错illegal rune literal
记录一下,今天运行一端代码遇到这个报错"illegal rune literal",代码如下: func main() { http.HandleFunc('/login', lo ...
- Golang报错:Cannot convert expression of type interface{} to type []byte
在使用golang实现后端登录逻辑的时候,碰到下面的问题:Cannot convert expression of type interface{} to type []byte 首先介绍下问题出现的 ...
- 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 ...
- 外显子分析报错解决方案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 ...
- 微信小程序 报错Setting data field "variableName" to undefined is invalid.
Setting data field "variableName" to undefined is invalid. 将数据字段“variableName”设置为未定义是无效的. ...
- Django中search fields报错:related Field has invalid lookup: icontains
models.py 文件 # coding:utf8from django.db import models class Book(models.Model): name = model ...
- 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 ...
- Spring Cloud 使用 FeignClient 启动报错
我们首先来看一下报错信息 Description: Field businessFeignClient in com.ysc.service.BusinessConfigService require ...
- 【ActiveMQ】消息生产者自动注入报错:Could not autowire. No beans of 'JmsMessagingTemplate' type found
使用ActiveMQ过程中,定义消息生产者: package com.sxd.jms.producer; import org.springframework.beans.factory.annota ...
随机推荐
- GitHub创建项目,保存代码。
平时学习会写一些代码,虽然只是零零散散的功能,但是基本都是在一个项目下操作,偶尔会忘记代码编辑顺序.国庆这几天在家,想把GitHub用起来,实现自己代码的可追溯,可查询.学习本篇博客,你需要一点的Gi ...
- 架构师养成记--22.客户端与服务器端保持连接的解决方案,netty的ReadTimeoutHandler
概述 保持客户端与服务器端连接的方案常用的有3种 1.长连接,也就是客户端与服务器端一直保持连接,适用于客户端比较少的情况. 2.定时段连接,比如在某一天的凌晨建立连接,适用于对实时性要求不高的情况. ...
- 基础概念——何为GNU与GCC
GNU:GNU 是一个自由软件操作系统.全称是GNU‘s Not Unix. GNU 是一款类似Unix的操作系统,它所采用的的典型内核是Linux. 该组合叫作GNU/Linux操作系统: GNU网 ...
- [JZOJ6075]【GDOI2019模拟2019.3.20】桥【DP】【线段树】
Description N,M<=100000,S,T<=1e9 Solution 首先可以感受一下,我们把街道看成一行,那么只有给出的2n个点的纵坐标是有用的,于是我们可以将坐标离散化至 ...
- HDU - 6096 处理后缀的字典树
题意:给定n个字符串,m次询问,每次询问多少个字符串前缀是pre且后缀是suf,前后缀不可相交 字典树同时存储前后缀,假设字符串长为len则更新2*len个节点,依次按s[0],s[len-1],s[ ...
- C#二进制位算 权限
关于权限管理,之前所做的都是一个权限对应一条数据,比方A页面有增删改查四个权限,那么用户在权限管理表中相对应AA页面有四条记录.后来改用二进制运算,发现省事很多. 首先说下位运算 熟悉一下操作符,懒得 ...
- 服务器端控件同html控件的区别
●ASP.NET中共有几种类型的控件? 三种:1-asp.net控件(动态) 2-标准的html控件(静态) 3-标准的html控件加runat="server"属性(动态) 动态 ...
- 六、python中context.get()方法
例:context.get('variant',False) 意思是如果context中不包括variant 就返回False.
- python描述符学习
目录 一.对象属性的访问控制 二.描述符基本理解 三.基本使用 四.使用描述符完成property.classmethod.staticmethod自定义实现 1.property的自定义实现 2.c ...
- Ubuntu16.04 下如何安装搜狗拼音输入法【亲测有效】
Ubuntu16.04 下如何安装搜狗拼音输入法[亲测有效] 一.添加fcitx键盘输入法系统[系统默认是iBus] 1.将下载源添加至系统源: sudo add-apt-repository p ...