Parameter Type
#include <iostream>
using namespace std;
class Xer{
public :
Xer(int x) { cout << "call Xer(int):" << x << endl; }
};
int f1(int) { cout << "call int f1(int)" << endl; return 0; }//1
int f1(double) { cout << "call int f1(double)" << endl; return 0; }//2
int f2(int) { cout << "call int f2(int)" << endl; return 0; }//3
int f2(char) { cout << "call int f1(char)" << endl; return 0; }//4
int f3(Xer) { cout << "call int f3(X)" << endl; return 0; }//5
int f3(...) { cout << "call int f3(...)" << endl; return 0; }//6
int main()
{
f1(4);//1:精确匹配
f2(true);//3:发生提升的匹配,true是bool类型,而4要求强制类型转换
f3(5);//5:调用用户自定义类型的转换的匹配,而6要求和省略号进行匹配
return 0;
}
const type
Non-template priority
Transition Sequence
class Base {
public:
operator short()const
{
cout << "Base operator()" << endl;
return 3;
}
};
class Drived : public Base {
};
void count(int x)
{
cout << "call count x" << x << endl;
}
void process(Drived const& x)
{
count(x);
}
int main()
{
Drived d;
process(d);
return 0;
}