1 // 2 // main.cpp 3 // test 4 // 5 // Created by Shaojun on 30/5/2020. 6 // Copyright © 2020 Shaojun. All rights reserved. 7 // 8 9 #include <iostream> 10 #include <stdio.h> 11 using namespace std; 12 13 14 int add1(int a, int b) 15 { 16 return (a + b); 17 } 18 19 class ADD 20 { 21 private: 22 int x,y; 23 public: 24 ADD() 25 { 26 27 } 28 int operator()(int x, int y) 29 { 30 return (x + y); 31 } 32 33 }; 34 35 36 template<typename T, typename U> 37 auto add3(T a, U b) -> decltype(a + b) 38 { 39 return a + b; 40 } 41 42 auto add4 = [](int a, int b) -> int 43 { 44 return a + b; 45 }; 46 47 48 int main(int argc, const char * argv[]) { 49 ADD add2; 50 std::cout << add1(3, 4) << std::endl; 51 std::cout << add2(3, 4) << std::endl; 52 std::cout << add3(3, 4) << std::endl; 53 std::cout << add4(3, 4) << std::endl; 54 return 0; 55 }