我用3个参数声明了一个C++函数声明,其中两个默认值是这样的.
void func(int const n, bool const flag=true, int *array=NULL) {
/* print contents of array */
}
Run Code Online (Sandbox Code Playgroud)
当我错误地调用函数时,省略第二个参数但包括第三个参数,就像这样
int array[5]={1,2,3,4,5};
func(5,array);
Run Code Online (Sandbox Code Playgroud)
gcc和intel编译器(Ubuntu 14.04 LTS上的默认编译器)都没有抱怨指定了最后一个参数而没有指定倒数第二个参数.代码运行但是为数组发送了NULL(我希望代码失败).
我的问题是为什么编译器没有抱怨它找不到匹配的函数,因为我的调用的签名应该出现为
funct(int const, int *)
Run Code Online (Sandbox Code Playgroud)
我可以在编译期间打开哪些选项来触发有关此错误使用的警告?