Function pointers with default parameters in C++

二次信任 提交于 2019-11-30 16:49:03

Both foo() and bar() can only be assigned to func_ptr2.

§8.3.6/2:

A default argument is not part of the type of a function. [Example:

int f(int = 0);

void h() {
    int j = f(1);
    int k = f(); // OK, means f(0)
}

int (*p1)(int) = &f; 
int (*p2)() = &f; // error: type mismatch

--end example]

Default argument cannot be provided for pointers to functions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!