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

Posted Ezharjan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}




作者:艾孜尔江

以上是关于C/C++四种方法实现加法操作_艾孜尔江撰的主要内容,如果未能解决你的问题,请参考以下文章

遍历时删除元素的方法

遍历时删除元素的方法

Linux上位指定文件夹创建软链接

Linux上位指定文件夹创建软链接

汇编语言中 加法(ADD)与带进位加法(ADC)有啥区别?

矩阵乘法AB=C的四种解释