首页 > 编程语言 > 详细

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

时间:2021-06-24 15:37:12      阅读:8      评论:0      收藏:0      [点我收藏+]
/*************************************************************************
	> 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;
}




作者:艾孜尔江

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

原文:https://www.cnblogs.com/ezhar/p/14925882.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!