如何确定/检查在编译时是否给出或省略了函数参数?
bool a_function(char* b, size_t len=0) {
// no run time check such as if (len ......
// just compile time check
// ...
}
如何实现?
不,没有办法知道(即使在运行时(是否为函数中具有默认参数的参数指定了参数。
您可以应用重载,例如
bool a_function(char* b, size_t len) {
// len is specified
// do something...
}
bool a_function(char* b) {
// len is not specified
// do something else...
// or call a_function with len=0 (the default value) if satisfying the requirement
}