重载是编译器自动匹配最佳的,和重载函数位置无关
#include"iostream"
#include"string"
using namespace std;
void test(int i){
cout<<"int"<<endl;
}
void test(string s){
cout<<"string"<<endl;
}
void main(){
char ch='a';
test(ch);
}
这样打印是int
#include"iostream"
#include"string"
using namespace std;
void test(string s){
cout<<"string"<<endl;
}
void test(int i){
cout<<"int"<<endl;
}
void main(){
char ch='a';
test(ch);
}
换顺序后打印的也是int
匹配是由编译器决定,和顺序无关