• C/C++四种方法实现加法操作_艾孜尔江撰


    /*************************************************************************
    	> File Name: add.cpp
    	> Author: Alexander
    	> Mail: mysoft@111.com
    	> Created Time: 一  8/24 20:16:39 2020
     ************************************************************************/
    
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <queue>
    #include <stack>
    #include <algorithm>
    #include <string>
    #include <map>
    #include <set>
    #include <vector>
    using namespace std;
    
    int add1(int a, int b) {
        return a + b;
    }
    
    class ADD {
    public :
        int operator()(int a, int b) {
            return a + b;
        }
    };
    
    //  泛型编程
    template<typename T, typename U>
    auto add3(T a, U b) -> decltype(a + b) {
        return a + b;
    }
    
    // 函数式编程
    auto add4 = [](int a, int b) -> int {
        return a + b;
    };
    
    int arr(int x) {
        return 2 * x;
    }
    
    int main() {
        ADD add2;
        cout << add1(3, 4) << endl;
        cout << add2(3, 4) << endl;
        cout << add3(3, 4) << endl;
        cout << add4(3, 4) << endl;
        
        int f[10];
        f[3];
        arr(3);
        return 0;
    }
    
    



    作者:艾孜尔江

  • 相关阅读:
    Lucene
    SQL优化以及索引
    Mysql优化
    RocketMQ
    RocketMQ
    Session共享
    Linux安装Nginx
    初识nginx
    跨域,防止表单重复提交
    HttpClient案例
  • 原文地址:https://www.cnblogs.com/ezhar/p/14925882.html
Copyright © 2020-2023  润新知