fork download
  1. /*****************************************************************
  2. Name :
  3. Date : 2017/04/04
  4. By : CharlotteHonG
  5. Final: 2017/04/04
  6. *****************************************************************/
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. template<class T, class T2>
  11. auto fun1(T a, T2 b) -> decltype(a+b){
  12. return a+b;
  13. }
  14.  
  15. template<class T, class T2>
  16. auto fun2(T a, T2 b){
  17. return a+b;
  18. }
  19.  
  20. template<class T, class T2>
  21. decltype(auto) fun3(T a, T2 b){
  22. return a+b;
  23. }
  24.  
  25.  
  26. /*==============================================================*/
  27. int main(int argc, char const *argv[]){
  28. cout << "fun=" << fun1(1, 1.5) << endl;
  29. cout << "fun=" << fun2(1, 1.5) << endl;
  30. cout << "fun=" << fun3(1, 1.5) << endl;
  31.  
  32. return 0;
  33. }
  34. /*==============================================================*/
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
fun=2.5
fun=2.5
fun=2.5