C++ 可以在自己的模板类中使用QMultiMap::conditerator吗?
我想使用C++ 可以在自己的模板类中使用QMultiMap::conditerator吗?,c++,qt,iterator,qmap,qmultimap,C++,Qt,Iterator,Qmap,Qmultimap,我想使用 QMultiMap<double, TSortable>::const_iterator it;` 导致 error: ‘it’ was not declared in this scope 每种用法。我尝试了迭代器,常量迭代器,甚至是速度较慢的迭代器,但都没有成功。甚至可以将Q(多重)映射与模板类一起使用吗?为什么定义(作为void*)正确时不能声明迭代器 我使用以下代码(包括省略): #包括 #包括 #包括 #包括 /**TSortable必须实现minDistan
QMultiMap<double, TSortable>::const_iterator it;`
导致
error: ‘it’ was not declared in this scope
每种用法。我尝试了迭代器
,常量迭代器
,甚至是速度较慢的迭代器
,但都没有成功。甚至可以将Q(多重)映射与模板类一起使用吗?为什么定义(作为void*)正确时不能声明迭代器
我使用以下代码(包括省略):
#包括
#包括
#包括
#包括
/**TSortable必须实现minDistance()和maxDistance()*/
模板
类优先级队列{
公众:
优先级队列(int limitTopCount)
:limitTopCount(limitTopCount),actMaxLimit(std::numeric\u limits::max())
{
}
虚拟~PriorityQueue(){}
私人:
void updateAttMaxLimit(){
if(maxMap.count()
GCC在您引用的错误之前给出此错误:
error: need ‘typename’ before ‘QMultiMap<double, TSortable>::const_iterator’ because ‘QMultiMap<double, TSortable>’ is a dependent scope
你说得对,不幸的是(事实证明…)我的GCC(4.4.4 ubuntu)即使使用-Wall
#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
};
error: need ‘typename’ before ‘QMultiMap<double, TSortable>::const_iterator’ because ‘QMultiMap<double, TSortable>’ is a dependent scope
typename QMultiMap<double, TSortable>::const_iterator it;