这两种定义接受另一个函数的函数的方式似乎是相同的(例如,两个函数的函数体是相同的)。我通过摆弄找到了第一个,然后在几个网站上找到了第二个。
void foo(int bar())
void foo(int (*bar)())
正文示例:
{
for (int i = 0; i < 10; i++)
cout << bar() << ' ';
}
有什么区别?一个比另一个更受欢迎吗?它是依赖于编译器还是 C++ 版本?
最佳答案
根据 function parameters declaration rules,它们是相同的.
The type of each function parameter in the parameter list is determined according to the following rules:
...
3) If the type is a function typeF
, it is replaced by the type "pointer toF
"
...
关于c++ - 两种函数作为参数传递方式的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58201394/