function-overloading/overloading-8.cc - A single best match again - slightly surprising perhaps. | Lecture 2 - slide 31 : 46 Program 9 |
#include <iostream> #include <string> #include "point.h" using namespace std; void f(char *c){ cout << "f(char *)" << endl; } void f(float c){ cout << "f(float)" << endl; } void f(string c){ cout << "f(string)" << endl; } void f(...){ cout << "f(...)" << endl; } int main(){ Point p(5.5); f(p); // A single best match: f(float) // the conversion operator point -> double, // and a double to float conversion // f(char *) and f(string) do not match at all. // f(...) matches, but it is in a lower matching category }