29 행은 컴파일에 질식 :C++ const를 혼란
void
CI_Metadata::get_record_metadata(const char* block, RecordInfoVector* record_info_vector) {
*record_info_vector = this->records.at(block); // <== LINE 29
return;
}
오류 :
CI_Metadata.cpp: In member function ‘void CI_Metadata::get_record_metadata(const char*, RecordInfoVector*)’:
CI_Metadata.cpp:29: error: invalid conversion from ‘const char*’ to ‘char*’
CI_Metadata.cpp:29: error: initializing argument 1 of ‘_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::at(const _Key&) [with _Key = char*, _Tp = std::vector<std::pair<char*, bool>, std::allocator<std::pair<char*, bool> > >, _Compare = std::less<char*>, _Alloc = std::allocator<std::pair<char* const, std::vector<std::pair<char*, bool>, std::allocator<std::pair<char*, bool> > > > >]’
나는이()에서 *는 const를 숯을하지 않음을 의미 가정합니다. 그렇다면 어떻게하면 에 저장된 벡터에 액세스합니까?> records.at (블록) 여기서 블록은 const char *입니까?
같이 const를 멀리 캐스팅. get_record_metadata()의 작성자는 char * 이상의 것을 고려할 수 없다. 그의 코드는 아직 준비가되지 않았으므로 대략 근사치를 작성하고 있습니다. 분명히 API를 준수해야합니다. (그러나 이것은 std :: string을 사용하기 시작한 또 다른 인수가 될 것입니다. char \ *가 현대 std :: world에서 그런 제 2 종 시민이 될지 전혀 몰랐습니다.) – Chap