Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 可以在自己的模板类中使用QMultiMap::conditerator吗?_C++_Qt_Iterator_Qmap_Qmultimap - Fatal编程技术网

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;