在模板函式中使用decltype時,我得到了編譯器錯誤。例子是不言自明的。幫助嗎?
template<class T>
void foo(T&& m)
{
auto t = (decltype(m)::value_type::second_type::value_type*)3; //compiler error
}
int main()
{
unordered_map<int, map<float, double >m。
foo(m);
auto t = (decltype(m)::value_type::second_type:: value_type*)3; // ok,t是一個std::pair<const float, double>*。
}
uj5u.com熱心網友回復:
如果你在函式中使用m,你需要洗掉參考(并添加typename):
示例:
typename std:: remove_reference_t<decltype(m)>:value_type::second_type::value_type* t。
或者直接使用T:
typename T::value_type::second_type::value_type* t。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/316111.html
標籤:
上一篇:如何使用列舉來專門化一個函式
