C++函数的重载

// 同一作用域下
// 函数名称相同
// 函数参数类型不同 或者 个数不同 或者顺序不同
//注意函数的返回值不可以作为函数的重载条件
void func(int a){ cout << "函数的重载" << endl; } void func(int a, int b){ cout << "函数的重载" << endl; } void func (){ cout << "函数的重载" << endl; } void func (double a){ cout << "函数的重载" << endl; } void func (double a,int b){ cout << "函数的重载" << endl; } void func (int a,double b){ cout << "函数的重载" << endl; }
//引用函数重载
void func(int &a){
    cout << "引用函数重载" << endl;
}

void func(const int &a){
    cout << "const引用函数重载" << endl;
}



int main(){
    int a = 10;
    int  &b =a;
    const int  &c = 10;
    func(10);
    func(a);
    return 0;
}

  

posted on 2022-11-18 10:05  知了不了了之  阅读(13)  评论(0编辑  收藏  举报