Go中的常量结构 [英] Constant struct in Go

查看:250
本文介绍了Go中的常量结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我不能创建常量结构?

  const FEED_TO_INSERT = quzx.RssFeed {0,

desc,
www.some-site.com,
upd_url,
img_title,
img_url,
0,
0,
0,
0,
0,
100,
alt_name,
1,
1,
1,
test,
100,
100,
0}
$ b


.\\rsrs_test.go:32:const初始值设定项quzx.RssFeed文字不是常量


解决方案

由于Go不支持结构常量(强调m
$ b


有布尔常量,符文常量,整型常量,
浮点常量,复常量,和字符串常量。
符文,整数,浮点和复数常量共同被称为数字常量

了解更多信息: https://golang.org/ref/spec#Constants


Why can't I create constant struct?

const FEED_TO_INSERT = quzx.RssFeed{ 0,
                    "",
                    "desc",
                    "www.some-site.com",
                    "upd_url",
                    "img_title",
                    "img_url",
                    0,
                    0,
                    0,
                    0,
                    0,
                    100,
                    "alt_name",
                    1,
                    1,
                    1,
                    "test",
                    100,
                    100,
                    0 }

.\rss_test.go:32: const initializer quzx.RssFeed literal is not a constant

解决方案

Because Go does not support struct constants (emphasis mine)

There are boolean constants, rune constants, integer constants, floating-point constants, complex constants, and string constants. Rune, integer, floating-point, and complex constants are collectively called numeric constants.

Read more here: https://golang.org/ref/spec#Constants

这篇关于Go中的常量结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆