C++(函数重载)

    科技2026-02-12  2

    在这里插入代码片

    #include"stdafx.h" #include using namespace std;

    //函数重载

    //符合条件 //1.在同一个作用域 //2.函数名称相同 //3. 函数参数类型不同,或者参数顺序不同,或个数不同

    double func(int a,int b,int c) { return a+b+c; }

    double func(double a,double b,double c) { return a+b+c; }

    double func(long a,long b,long c) { return a+b+c; }

    //函数的返回值类型不能作为函数重载的条件

    int main() { double a,b,c; cout<<“输入三个数求和”<<endl; cin>>a>>b>>c;

    cout<<“和为:”<<func(a,b,c)<<endl;

    system("pause"); return 0;

    }

    Processed: 0.019, SQL: 9