How to declare a function return a pointer to function return pointer to int[3]

I'm trying the following declarations:

int (*(*((*foo)(const void *))()))[3];

and

int (*(*(*foo)(const void *)()))[3];

But the compiler gives me an error:

error: 'foo' declared as function returning a function

DEMO

Is it possible at all in c++?


The way that derived declarations work is that you replace the identifier in the declaration with the new thing you are deriving. For example in the first step here, to get from "pointer to int[3]" to "function returning pointer to int[3]", we take the declaration for "pointer to int[3]", and change the identifier to be a function declarator.

A pointer to int[3]: int (*name)[3];

A function returning that: int (* name() )[3];

A pointer to that: int (* (*name) () )[3] - parentheses required otherwise the * binds to the other * instead of to name

A function returning that: int (* (* name() ) () )[3]


Like this:

int (*(*f())())[10];

or even cleaner (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]
链接地址: http://www.djcxy.com/p/78656.html

上一篇: 为什么typedef模板是非法的?

下一篇: 如何声明一个函数返回一个指向函数的指针返回指向int [3]