2013-11-26 4 views
0

이 코드는 컴파일되지 않습니다 :const 매개 변수가있는 메소드는 const가 아닌 매개 변수를 허용하지 않습니다.

ErrorTolerantSearchTest.cpp: In member function ‘virtual void ErrorTolerantSearchTest_computeUnion_Test::TestBody()’: 
ErrorTolerantSearchTest.cpp:89:50: error: no matching function for call to ‘ErrorTolerantSearch::computeUnion(std::vector<std::map<unsigned int, unsigned int>*>&)’ 
ErrorTolerantSearchTest.cpp:89:50: note: candidate is: 
In file included from ErrorTolerantSearchTest.cpp:36:0: 
./ErrorTolerantSearch.h:56:19: note: std::map<unsigned int, unsigned int> ErrorTolerantSearch::computeUnion(const std::vector<const std::map<unsigned int, unsigned int>*>&) 
./ErrorTolerantSearch.h:56:19: note: no known conversion for argument 1 from ‘std::vector<std::map<unsigned int, unsigned int>*>’ to ‘const std::vector<const std::map<unsigned int, unsigned int>*>&’ 
make[1]: *** [ErrorTolerantSearchTest] Fehler 1 

그러나 문제가 무엇 :

ErrorTolerantSearch e; 
e.readStringsFromFile("test.txt"); 
e.buildQgramIndex(3); 
vector<map<uint, uint>*> lists; 
lists.push_back(&e._qgramIndex["ret"]); // ignore this, assume container not empty 
lists.push_back(&e._qgramIndex["coo"]); // ignore this, assume container not empty 
map<uint, uint> resunion = e.computeUnion(lists); // <-- this makes problems 

이 헤더

class ErrorTolerantSearch { 
public: 
    void readStringsFromFile(string fileName); 
    void buildQgramIndex(uint q); 
    map<uint, uint> computeUnion(const vector<const map<uint, uint>*> & lists); 
    map<string, map<uint, uint> > _qgramIndex; 
}; 

이 컴파일러 오류를 준다의 일부인가? 나는 그것을 얻지 않는다. 비 const 변수를 참조로 const 매개 변수가있는 함수에 전달할 때 문제가 발생하지 않았습니다.

답변

5

std::vector<const T>std::vector<T>과 같지 않으며 변환 할 수 없습니다.

관련 문제