gpt4 book ai didi

go - 未命名指针返回值的预期标识符

转载 作者:数据小太阳 更新时间:2023-10-29 03:22:23 25 4
gpt4 key购买 nike

gofmt 此时给出关于此函数签名的“预期标识符”警告:

func foo() (*int, y int) {}
^

但是,它不会提示这个签名:

func foo() (int, y int) {}

如何命名一个返回值而不让 gofmt 提示未命名的指针返回值?

最佳答案

How can I name one return value without having gofmt complain about the unnamed pointer return value?


The Go Programming Language Specification

Blank identifier

The blank identifier is represented by the underscore character _. It serves as an anonymous placeholder instead of a regular (non-blank) identifier and has special meaning in declarations, as an operand, and in assignments.


使用空白标识符 (_)。例如,

package main

func foo() (_ *int, y int) { return nil, 0 }

func main() {}

Playground :https://play.golang.org/p/RBfxkDaZdOB

关于go - 未命名指针返回值的预期标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51560430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com