考虑这篇MSDN文章(“默认参数”)以及以下代码:
文章称“可以为指向函数的指针提供默认参数。例如:
#include <stdio.h>
void print(int x) {
printf("%d\n", x + 537);
}
typedef void (*Func)(int x = 0);
int main() {
Func f = print;
f();
return 0;
}
文章称“可以为指向函数的指针提供默认参数。例如:
int (*pShowIntVal)( int i = 0 );
”。我理解是上述代码应该能够成功编译。但是,实际上并不行:a.cpp
a.cpp(7) : error C2383: 'Func' : default-arguments are not allowed on this symbol
a.cpp(11) : error C2198: 'Func' : too few arguments for call
看来我误解了这篇文章。它的重点是什么,正确的解释是什么?
int (*pShowIntVal)( int i = 0 );
!“错误2383:'pShowIntVal':不允许此符号使用默认参数”。 - Earth Engine