I'm new to Golang and would like to have the following assignment explained

huangapple go评论65阅读模式
英文:

I'm new to Golang and would like to have the following assignment explained

问题

我是你的中文翻译助手,以下是翻译好的内容:

我对Golang还不熟悉,希望能对下面的代码进行解释,特别是在最后一部分赋值Pos(0)时。Pos(0)具体是什么意思?谢谢!

type Pos uint

var NoPos = Pos(0)

在这段代码中,Pos是一个自定义的类型,它是一个无符号整数类型。NoPos是一个变量,它的类型是Pos,并且被赋值为Pos(0)Pos(0)表示将整数值0转换为类型Pos。这样做的目的可能是为了在代码中使用NoPos来表示一个特殊的位置,即没有具体位置的情况。

英文:

I'm new to Golang and would like to have the following code explained to me, particularly the last part when you assign Pos(0). What is Pos(0) exactly? Thanks!

type Pos uint

var NoPos = Pos(0)

答案1

得分: 3

这是一个类型转换。它用于将0转换为Pos类型。也可以不使用转换来重写它,像这样:

var NoPos Pos = 0
英文:

It's a type conversion. It is there to convert 0 to type Pos. It could also be rewritten without a conversion like this:

var NoPos Pos = 0

huangapple
  • 本文由 发表于 2015年11月9日 20:19:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/33608975.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定