2013-06-29 3 views
0

데이터 (두 번째 필드)를 기준으로 std::map을 정렬하려고합니다. 그러나 두 번째 필드 자체는 구조체이며 해당 요소 중 하나를 기반으로 정렬하려고합니다. herereference이 무엇인지에 따라지도를 벡터에 복사 한 다음 std::sort을 사용하기로 결정했습니다. 여기에 나는데이터를 기준으로 std :: map 정렬 (map-> vector-> sort)

error C2275: illegal use of this type as an expression 
error C2059: syntax error : ')' 

내가 무엇을 놓친 않은이 오류, 클래스 implementtion 정렬 기능의 라인에서

#include <iostream> 
#include <vector> 
#include <map> 
#include <utility> 

class foo() { 
    foo() {} 
    void bar() 
    { 
     aDeltaMap theDeltaMap; 
     // insert some elements to theDeltaMap 
     aDeltaVector theDeltaVec(theDeltaMap.begin(), theDeltaMap.end()); 
     std::sort(theDeltaVec.begin(), theDeltaVec.end(), descend_rep<deltaPair>()); //ERROR 
    } 
private: 
    typedef struct entry { 
     entry(int r, int mc) : rep(r), missCounter(mc) {} 
     int rep; 
     int missCounter; 
    } aDeltaEntry; 

    typedef std::map< int, aDeltaEntry > aDeltaMap; 
    typedef std::pair< int, aDeltaEntry > deltaPair; 
    typedef std::vector<deltaPair> aDeltaVector; 
    struct descend_rep 
     : std::binary_function<deltaPair,deltaPair,bool> 
     { 
     inline bool operator()(const deltaPair& lhs, const deltaPair& rhs) { return lhs.second.rep > rhs.second.rep; }; 
     }; 
}; 

입니까?

답변

1

한 오류가 descent_rep가 클래스 템플릿되지 않는 것입니다, 그래서 당신은 당신은 그것의 피연산자 수행을 비교하기 때문에, bool operator()const 너무 descend_rep의를해야

descend_rep() 

에 의해

descend_rep<deltaPair>() 

를 교체해야 그 상태를 바꾸지 마라.

+0

대단히 감사합니다. 하나의 데이터 유형 만 있기 때문에 템플릿을 작성할 필요가 없다고 생각했습니다. 그런 다음 템플릿을 삭제하는 것을 잊었습니다. – mahmood