2013-08-25 1 views
0

벡터의 정렬 된 숫자 인덱스를 생성해야합니다. 그리고 다른 필드에 비해 T * 세트를 만듭니다.비교기 유형 오류

이 dosnt 컴파일 : 부울 비교기 :: 연산자() (const를 valType &, const를 valType &) CONST : 캔트 "CONST POI &"의 "POI의 *의 CONST"에서 타입 캐스팅을합니다.

POI 2 필드 라벨 (표준 : : 문자열), 유형 (단위)

template <typename FieldType, typename valType, FieldType valType::*iMember> 
class Comparator 
{ 
public: 
    bool operator()(valType const& iLeft, valType const& iRight) const { 
     return iLeft->*iMember > iRight->*iMember; 
    } 
}; 

template< class ValType, class CompType, typename FieldType > 
class SearchIndex 
{ 
public: 
    SearchIndex() {} 
    void Build(std::vector<ValType> iElems, std::ofstream & oStream) 
    { 
     std::map< ValType *, size_t > numbersOfElems; 

     for(std::vector<ValType>::iterator it = iElems.begin(); it != iElems.end(); ++it){ 
      m_elems.insert(&(*it)); 
      numbersOfElems.insert(std::pair< ValType * , size_t>(&(*it),5)); 
     } 

     oStream << m_elems.size(); 
     for(std::multiset< ValType * >::iterator it = m_elems.begin(); it!= m_elems.end(); ++it) 
      oStream << numbersOfElems[*it] << " " ; 
    } 

private: 
    std::multiset< ValType * , CompType > m_elems; 
}; 

MAIN.CPP이

int main(int argc, char *argv[]) 
{ 
    std::vector<POI> testVect; 

    POI sec("Gas", 1); 
    testVect.push_back(sec); 
    POI th("Tryy", 3); 
    testVect.push_back(th); 

    std::ofstream oStream; 
    oStream.open("Index.dat",std::ofstream::app | std::ofstream::binary | std::ofstream::out); 

    typedef Comparator<std::string, POI, &POI::m_label> POIbyLabel; 

    SearchIndex< POI, POIbyLabel, std::string> testIndex; 

    testIndex.Build(testVect, oStream); 
} 

답변

0

& (*이) 경우 Searchindex에서 "POI의 *"를 입력입니다 반면 Comparator의 accepting 매개 변수는 "const POI"(valType const &)입니다. m_elems.insert (* it)를 사용해보십시오;

+0

이것은 도움이되지 않습니다. std :: multiset m_elems; – YYY

+0

죄송합니다,이 부분은 놓쳤습니다. 그렇다면 POI 참조 유형 인 "valType const & iLeft"를 허용하기 때문에 bool operator() (valType const & iLeft, valType const & iRight)의 정의를 변경해야한다고 생각하지만 "std :: multiset "은 POI 포인터 유형입니다. "bool operator() (valType const * iLeft, valType const * iRight)" "bool operator() (valType const * iLeft, valType const * iRight)"로 변경할 수 있습니다. 바라기를 이것은 잘 작동 할 것입니다. @Ubitso – JackyZhu

+0

나는 그걸 알레 지역에 맡겼다. 타이. – YYY