[英]How to declare a function return a pointer to function return pointer to int[3]
我正在嘗試以下聲明:
int (*(*((*foo)(const void *))()))[3];
和
int (*(*(*foo)(const void *)()))[3];
但是編譯器給我一個錯誤:
error: 'foo' declared as function returning a function
在c ++中有可能嗎?
像這樣:
int (*(*f())())[10];
甚至清潔劑(kinda):
using array_type = int (*)[10];
using return_type = array_type (*)();
return_type f();
使用cdecl 。
cdecl> declare f as function returning pointer to function returning pointer to array 3 of int
int (*(*f())())[3]
派生聲明的工作方式是用派生的新事物替換聲明中的標識符。 例如,在第一步中,要從“將指針指向int [3]”到“將指針返回到int [3]的函數”,我們需要聲明“將指針指向int [3]”,並將標識符更改為是一個函數聲明器。
指向int [3]的指針: int(* name)[3];
返回以下內容的函數:int(* name() )[3];
指向它的指針:int(* (* name) ())[3]-需要括號,否則*
綁定到另一個*
而不是name
返回以下內容的函數:int(*(*(* name() )())[3]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.