我正在学习如何在我的C++大学课程中使用矢量。我遇到了一个让我无法使用带矢量迭代器的问题。这是我的源代码:如何增加矢量迭代器?
template <class T>
void HuffMan<T>::search_freq(T temp) {
//checks for frequency
if(objects.empty()){
objects.push_back(temp);
return;
}
vector<T>::iterator it = objects.begin();
while(it != objects.end()) {
if(*it == temp)
cout<<"added aready\n";
else
objects.push_back(temp);
//this is where the error occurs
//I cannot call 'it++' for some reason
it++;
}
}
该代码总是返回一个运行时错误,指出'vector iterator not incrementable'。我试图将while循环改为for循环,但我不认为这与错误有关。
信息:我的矢量对象声明如下:
vector<T> objects;
谁能帮我针点这个错误?
感谢, Y_Y
包含了'霍夫曼'类的方法内while循环? –
2010-11-07 03:38:34