更新时间:2021-09-14 22:43:39
没有你不能重载函数正在传递的参数的值的基础,因此也不允许基于默认参数的值重载。
No you cannot overload functions on basis of value of the argument being passed, So overloading on the basis of value of default argument is not allowed either.
您只能在以下基础上重载函数:
You can only overload functions only on the basis of:
const
和 volatile
。const
and volatile
.编译器接受重载取决于事实:
如果编译器明确地解析了函数的调用。
Ofcourse, Whether the overload is accepted by the compiler depends on the fact:
If the compiler resolve calling of the function unambiguously.
在你的情况下,编译器不能解决歧义,例如:如果你简单地调用函数,编译器不知道调用哪个重载函数:
In your case, the compiler cannot resolve the ambiguity, for ex: The compiler wouldn't know which overloaded function to call if you simple called the function as:
foo(100);
编译器无法做出决定,因此无法执行错误。
The compiler cannot make the decision and hence the error.