Valid overloaded function call marked as error (6. Basic Concepts V)
binary-manu opened this issue · comments
Emanuele Giacomelli commented
This page says:
but then the call taking a single char
literal is marked as an error. However, it does compile.
Of the available overloads of f
, only 2 can be called with a single argument, but f(float)
implies a conversion, while f(int)
uses integral promotions, as listed in the rule bullets. Thus, f(int)
is selected since it has higher priority.
#include <iostream>
void f(int a) {
std::cout << "int here!\n";
}
void f(float b) {
std::cout << "float here!\n";
}
void f(float b, char c) {
std::cout << "float and char here!\n";
}
int main() {
f(0);
f('a');
f(2.3f);
//f(2.3);
f(2.3, 'a');
}
/*
Output:
int here!
int here!
float here!
float and char here!
*/
Federico commented
thanks, @binary-manu. Definitely a mistake on my side. Here the slide updated with some improvements