function-overloading/overloading-3.cc - 'Float to double' conversion prefered over 'float to int' and 'float to long int'. | Lecture 2 - slide 31 : 46 Program 4 |
#include <iostream> #include <string> using namespace std; void f(int i){ cout << "f(int)" << endl; } void f(long int i){ cout << "f(long int)" << endl; } void f(double d){ cout << "f(double)" << endl; } int main(){ float c = 5.5; f(c); // A single best match: f(double) // The float to double promotion is in another category than // float -> int and float -> long int. }