46 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
void f(int) {
std::cout << "Calling function f(int)" << std::endl;
}
void f(double) {
std::cout << "Calling function f(double)" << std::endl;
}
void f(char*) {
std::cout << "Calling function f(char*)" << std::endl;
}
/*
template <typename T>
void f(T) {
std::cout << "Calling function that is instantiated from template" << std::endl;
}
*/
void f(int, double) {
std::cout << "Calling function f(int, double)" << std::endl;
}
void f(double, double) {
std::cout << "Calling function f(double, double)" << std::endl;
}
/*
void f(double, int) {
std::cout << "Calling function f(double, int)" << std::endl;
}
*/
int main() {
f('a'); // f(int) numeric promotion
f(0); // f(int) exact match
//long a=5L;
//f(a); //ambiguous, long to int, and long to double are standard conversions
//f(double(a)); // ambiguity is resolved by explicit conversion
// 1. parameter {f1} 2.parameter {f1, f2}: {f1} intersection {f1, f2} = {f1}
f('a', 1); // f(int, double)
return 0;
}