c++模板后置返回类型

#include "iostream"

using namespace std;


template  auto compare(const T &t1,const T &t2) -> typename remove_reference::type {
    return t1 > t2 ? t1 : t2;
};


template  auto compare1(const T &t1,const T &t2) -> typename remove_reference::type {
    return t1 > t2 ? t1 : t2;
};

int main(){


    auto a = compare(73,928);
    auto b = compare1(73,928);
    std::cout << " a = " << a <$ g++ func.cpp -std=c++11

结果:

$ ./a.exe
 a = 928
 b = 928
 c = 92

 

你可能感兴趣的:(c++)