5free

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

转自: https://blog.csdn.net/m0_51955470/article/details/117960694

 

#include <iostream>
using namespace std;

//template<typename R,typename T,typename U>
//R add01(T t, U u)
//{
//    return t + u;
//}


template <typename T, typename U>
auto add(T t, U u)->decltype(t + u)
{
    return t + u;
}

int main()
{
    int x = 520;
    double y = 13.14;
    auto ret = add<int, double>(x, y);
    auto ret01 = add(x, y);
    cout << ret << endl;
    cout << ret01 << endl;
    return 0;
}

 

例2

auto f() -> int
{
    return 999;
}

int main()
{
    return f();
}

 

 

扩展:

怎么理解C++11的返回类型后置  https://www.yisu.com/zixun/567380.html

posted on 2022-10-20 12:54  5free  阅读(15)  评论(0编辑  收藏  举报