所以我得到了以下表达式:
int (*f1(int(*a)(int, int))) (int, int);
我正试图弄清它的意义,但它令人困惑。我发现“a”是一个指向带有 2 个参数(int,int)的函数的指针。 然后 f1 似乎是指向另一个函数的指针,该函数接受 2 个 int 参数。 但令我困惑的是 f1 与 a 的关系。
谁能给我一些提示或正确解释上面的表达式在做什么?
最佳答案
它将 f1
声明为一个带有名为 a
的参数的函数。参数类型和返回类型都是“指向函数的指针,带有两个返回 int
的 int
参数”。
这是你解析它的方式:
// f1 is...
f1
// ...a function...
f1( )
// ...with a single parameter called `a`, which is...
f1( a )
// ...a pointer to...
f1( *a )
// (skip parentheses)
f1( (*a) )
// ...a function...
f1( (*a)( ))
// ...with two `int` parameters...
f1( (*a)(int, int))
// ...returning an `int`. The `f1` itself returns...
f1(int(*a)(int, int))
// ...a pointer to...
*f1(int(*a)(int, int))
// (skip parentheses)
(*f1(int(*a)(int, int)))
// ...a function...
(*f1(int(*a)(int, int))) ( )
// ...with two int parameters...
(*f1(int(*a)(int, int))) (int, int)
// ...returning an `int`.
int (*f1(int(*a)(int, int))) (int, int)
关于c++ - 函数指针表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48240050/