zoukankan      html  css  js  c++  java
  • 深入函数

    1:普通函数的重载

    /*普通函数的重载:
    我们可以将一个相同名字但是不同类型的函数重复调用多次来处理不同类型的数据
    由于参数不同,编译器根据参数类型调用不同的函数,输出不同的结果*/
    #include <iostream>
    using namespace std;
    void func(int);
    void func(long);
    void func(float);
    void func(double);
    int main()
    {
        int a = 1;
        long b = 10000;
        float c = 1.5;
        double d = 6.4579;
        cout << "a:" << a << endl;
        cout << "b:" << b << endl;
        cout << "c:" << c << endl;
        cout << "d:" << d << endl;
        func(a);
        func(b);
        func(c);
        func(d);
        return 0;
    }
    void func(int a)
    {
        cout << "a的平方为:" << a*a << endl;
    }
    void func(long a)
    {
        cout << "b的平方为:" << a*a << endl;
    }
    void func(float a)
    {
        cout << "c的平方为:" << a*a << endl;
    }
    void func(double a)
    {
        cout << "d的平方为:" << a*a << endl;
    }

     2:成员函数的重载

    /*成员函数的重载*/
    #include <iostream>
    using namespace std;
    class cube
    {
    public:
        void sum();
        void sum(int x, int y);
    private:
        int i;
        int j;
    };
    int main()
    {
        cube a;
        a.sum(2, 3);
        a.sum();
        return 0;
    }
    void cube::sum()
    {
        cout << "i的平方为:" << i*i << endl;
        cout << "j的平方为:" << j*j << endl;
    }
    void cube::sum(int x, int y)
    {
        i = x;
        j = y;
        cout << "i:" << i << "	" << "j:" << j << endl;
    }
  • 相关阅读:
    leetcode1118
    Kaggle练习002--Predict survival on the Titanic(Titanic Disaster)
    leetcode1111
    leetcode1110
    leetcode1109
    练习题|网络编程-socket开发
    web网页练习
    Bootstrap框架
    JQuery框架2.位置属性|筛选方法|事件
    Jquery框架1.选择器|效果图|属性、文档操作
  • 原文地址:https://www.cnblogs.com/rain-1/p/4855071.html
Copyright © 2011-2022 走看看