2011-09-18 2 views
1

나는QMultiMap :: ConstIterator를 자체 템플릿 클래스에 사용할 수 있습니까?

QMultiMap<double, TSortable>::const_iterator it;` 

을 사용하여 이상 QMultiMap 반복하고 싶지만 컴파일러는 모든 사용에 대한

error: ‘it’ was not declared in this scope 

결과

error: expected ‘;’ before ‘it’ 

을 뿌려줍니다. 나는 ConstIterator, const_iterator 그리고 심지어 더 느린 Iterator을 아무런 성공없이 시도했다. Q (Multi) Map을 템플릿 클래스와 함께 사용할 수 있습니까? 정의 (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 
}; 

답변

2

GCC 당신이 인용 한 전에이 오류를 제공합니다 : 문제를 설명

error: need ‘typename’ before ‘QMultiMap<double, TSortable>::const_iterator’ because ‘QMultiMap<double, TSortable>’ is a dependent scope 

내가 다음 코드를 사용하여 (생략 경비를 포함한다). typename 키워드를 추가

typename QMultiMap<double, TSortable>::const_iterator it; 

을 그리고 만들 것이다.

+0

내 GCC (4.4.4 우분투)는'-Wall'에서도 오류를 표시하지 않습니다. – mbx

관련 문제