C++11 STL 关键字decltype

decltype可让编译器找出表达式的类型。

map<string,float> coll;
decltype(coll)::value_type elem;

新的函数声明语法

template<typename T1, typename T2>
auto add(T1 x, T2 y) -> decltype(x+y){
    return x+y;
}

float c=add(5.4f,3);
cout<<"c="<<c<<endl;

 

posted @ 2020-05-09 22:04  啸傲风月  阅读(239)  评论(0编辑  收藏  举报