'std::vector<T>::iterator it;' doesn't compile

心已入冬 提交于 2019-12-03 23:04:29

Try this instead:

typename std::vector<T>::iterator it;

Here's a page that describes how to use typename and why it's necessary here.

What you are doing is inefficient. Use a binary search instead:

#include <algorithm>

template <typename T>
void insertItem(std::vector<T>& v, const T& x)
{
    v.insert(std::upper_bound(v.begin(), v.end(), x), x);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!