1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | template<typename T> void f(T a, T b) {} float get_value() //consider this too! { return 1.0; } int main() { f(get_value(), 1); //compilation error f(get_value(), 1.0); //compilation error f(get_value(), 1.0f); //okay } |
CnRlbXBsYXRlPHR5cGVuYW1lIFQ+CnZvaWQgZihUIGEsIFQgYikge30KCmZsb2F0IGdldF92YWx1ZSgpIC8vY29uc2lkZXIgdGhpcyB0b28hCnsKCXJldHVybiAxLjA7Cn0KaW50IG1haW4oKQp7CglmKGdldF92YWx1ZSgpLCAxKTsgICAvL2NvbXBpbGF0aW9uIGVycm9yCglmKGdldF92YWx1ZSgpLCAxLjApOyAvL2NvbXBpbGF0aW9uIGVycm9yCglmKGdldF92YWx1ZSgpLCAxLjBmKTsgLy9va2F5CQp9Cg==
prog.cpp: In function ‘int main()’: prog.cpp:11: error: no matching function for call to ‘f(float, int)’ prog.cpp:12: error: no matching function for call to ‘f(float, double)’
-
result: Compilation error (maybe you wish to see an example for C++ 4.7.2)


