我正在学习 Go 中的指针。并设法写下类似的东西:
func hello(){
fmt.Println("Hello World")
}
func main(){
pfunc := hello //pfunc is a pointer to the function "hello"
pfunc() //calling pfunc prints "Hello World" similar to hello function
}
有没有办法声明函数指针而不像上面那样定义它?我们可以像在 C 中那样写一些东西吗?
例如 void (*pfunc)(void);
原文由 Kevin 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果您使用签名,它会起作用。没有指针。
或者,您可以直接使用函数签名,而无需声明新类型。