1
我想用是否可以在自己的模板類中使用QMultiMap :: ConstIterator?
QMultiMap<double, TSortable>::const_iterator it;`
遍歷一個QMultiMap
但是編譯器會抱怨
error: expected ‘;’ before ‘it’
導致
error: ‘it’ was not declared in this scope
在每次使用。我試過ConstIterator
,const_iterator
甚至更慢的Iterator
沒有任何成功。是否可以使用Q(多)地圖與模板類?爲什麼我無法在定義(如void *)定義時聲明Iterator?
我用下面的代碼(包括後衛略):
#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
};
你是對的,不幸的是(事實證明...)我的GCC(4.4.4 ubuntu)即使使用'-Wall'也不顯示該錯誤 – mbx