函数
一、 重载函数
- 作用:采用相同的函数名称,提高函数复用性
- 函数满足重载(共存)条件:
(1) 相同的作用域;
(2)函数名相同;、
(3)函数形参的个数、类型、顺序不同
void func(){
std::cout<< "func()" <<std::endl;
}
void func(int &a){
std::cout<< "func(int a)"<< std::endl;
}
void func(const int &a){
std::cout<< "func(const int &a)" << std::endl;
}
void func(double a){
std::cout << "func(double a)" << std::endl;
}
void func(int a, double b){
std::cout << "func(int a, double b)" << std::endl;
}
void func(double a, int b){
std::cout << "func(double a, int b)" << std::endl;
}
int main(){
int a = 10;
func(a);
func(10);
return 0;
}