Go中函数名称之前的参数?

编程入门 行业动态 更新时间:2024-10-27 07:21:56
本文介绍了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中函数名称之前的参数?

本文发布于:2023-10-26 08:06:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529583.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   名称   参数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!