Tôi đã có chức năng này:'std :: vector <T> :: iterator it;' không biên dịch
template<typename T>
void Inventory::insertItem(std::vector<T>& v, const T& x)
{
std::vector<T>::iterator it; // doesn't compile
for(it=v.begin(); it<v.end(); ++it)
{
if(x <= *it) // if the insertee is alphabetically less than this index
{
v.insert(it, x);
}
}
}
và g ++ cung cấp cho các lỗi này:
src/Item.hpp: In member function ‘void
yarl::item::Inventory::insertItem(std::vector<T, std::allocator<_CharT> >&, const T&)’:
src/Item.hpp:186: error: expected ‘;’ before ‘it’
src/Item.hpp:187: error: ‘it’ was not declared in this scope
nó phải là một cái gì đó đơn giản, nhưng sau mười phút nhìn chằm chằm vào nó, tôi có thể' t tìm thấy bất cứ điều gì sai trái. Bất cứ ai khác nhìn thấy nó?
btw, bạn không nên sử dụng 'it