Content #
By using the new decltype keyword, you can let the compiler find out the type of an expression.
下面的C++ Template声明的函数,注意其返回值类型声明。
template <typename T1, typename T2>
decltype(x + y) add(T1 x, T2 y);
现有如下C++声明的map:
std::map<std::string, float> coll;
用C++11的decltype关键词来声明map中的value_type变量elem:
decltype(coll)::value_type elem;