1、默认参数一般在函数声明中提供,如果程序中既有函数声明又有函数定义,函数定义中不允许再定义参数的默认值,即使指定的默认值完全相同也不行。
下面是错误的,默认参数不能同时出现在函数声明与函数定义中:
// ff.h
int ff(int = 0);
// ff.cc
#include "ff.h"
int ff(int i = 0) { /* ... */ } // error
2、如果程序中只有函数定义,没有函数声明,则默认参数可以出现在函数定义中。并且:
If a default argument is provided in the parameter list of a function definition, the default argument is available only for function calls in the source file that contains the function definition.
3、所有默认参数必须放在参数表的最后。