- Modern C++:Efficient and Scalable Application Development
- Richard Grimes Marius Bancila
- 155字
- 2021-06-10 18:28:06
Overloading functions
You can have several functions with the same name, but where the parameter list is different (the number of parameters and/or the type of the parameters). This is overloading the function name. When such a function is called, the compiler will attempt to find the function that best fits the parameters provided. If there is not a suitable function, the compiler will attempt to convert the parameters to see if a function with those types exists. The compiler will start with trivial conversions (for example, an array name to a pointer, a type to a const type), and if this fails the compiler will try to promote the type (for example, bool to int). If that fails, the compiler will try standard conversions (for example, a reference to a type). If such conversions results in more than one possible candidate, then the compiler will issue an error that the function call is ambiguous.