[英]Using decltype to initialise container
當我取消引用容器的迭代器(例如*v.begin()
)時,總是得到對所包含類型的引用。 然后,我不能使用decltype
初始化另一個容器。
int main()
{
vector<int> a;
vector<decltype(*a.begin())> b;
return 0;
}
我該如何解決?
選擇1:
聲明b
的最簡單方法是使用decltype(a)
作為容器類型。
decltype(a) b;
選擇2:
聲明b
的下一層間接性是使用decltype(a)::value_type
作為包含的類型。
std::vector<decltype(a)::value_type> b;
選擇3:
聲明b
的最round回的方法是使用std::remove_reference
從取消引用的迭代器中刪除引用。
std::vector<std::remove_reference<decltype(*a.begin())>::type> b;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.