本文介绍了Go中函数名称之前的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看过一些Go函数定义如下:
I have seen some Go functions defined like this:
type poly struct { coeffs [256]uint16 } func (p *poly) reset() { for i := range p.coeffs { p.coeffs[i] = 0 } }稍后您可以通过以下方式致电
Which you can later call as:
var p poly p.reset()在我所知道的其他编程语言中,我还没有看到这一点.重置功能中 p * poly 的目的是什么?它看起来像一个函数参数,但写在函数名称之前.有任何澄清吗?
I haven't seen this in other programming languages that I know. What's the purpose of p *poly in the reset function? It seems to be like a function parameter but written before the function name. Any clarification for it?
推荐答案这意味着 reset()是 * poly 上的一种方法.这是非常基本的Go;您确实需要从开始旅行开始.在没有基本了解其语法的情况下尝试阅读Go将会非常混乱.
It means that reset() is a method on *poly. This is very basic Go; you really need to start with the Go tour. Trying to read Go without a basic understanding of its syntax is going to be very confusing.
更多推荐
Go中函数名称之前的参数?
发布评论