【发布时间】:2011-09-18 13:28:55
【问题描述】:
我想使用
遍历QMultiMap
QMultiMap<double, TSortable>::const_iterator it;`
但编译器抱怨
error: expected ‘;’ before ‘it’
导致
error: ‘it’ was not declared in this scope
适用于各种用途。我尝试了ConstIterator、const_iterator,甚至更慢的Iterator,但都没有成功。甚至可以将 Q(Multi)Map 与模板类一起使用吗?为什么定义(作为 void*)没问题时我不能声明迭代器?
我使用下面的代码(包括守卫省略):
#include <QtCore/QDebug>
#include <QtCore/QMap>
#include <QtCore/QMultiMap>
#include <limits>
/** TSortable has to implement minDistance() and maxDistance() */
template<class TSortable>
class PriorityQueue {
public:
PriorityQueue(int limitTopCount)
: limitTopCount_(limitTopCount), actMaxLimit_(std::numeric_limits<double>::max())
{
}
virtual ~PriorityQueue(){}
private:
void updateActMaxLimit(){
if(maxMap_.count() < limitTopCount_){
// if there are not enogh members, there is no upper limit for insert
actMaxLimit_ = std::numeric_limits<double>::max();
return;
}
// determine new max limit
QMultiMap<double, TSortable>::const_iterator it;
it = maxMap_.constBegin();
int act = 0;
while(act!=limitTopCount_){
++it;// forward to kMax
}
actMaxLimit_ = it.key();
}
const int limitTopCount_;
double actMaxLimit_;
QMultiMap<double, TSortable> maxMap_;// key=maxDistance
};
【问题讨论】:
标签: c++ qt iterator qmap qmultimap