線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> > > > >]’
我假定這意味着在()不會拿常量字符*。那麼,如何訪問存儲在this-> records.at(block)中的矢量,其中block是const char *?
不幸的是,我*必須*通過爲const char \ *。 get_record_metadata()的作者不能或不會超越char *。他的代碼還沒有準備好,所以我寫了一個粗略的近似值,顯然必須符合API。 (但是,這將成爲他開始使用std :: string的另一個參數 - 我不知道char \ *在現代std :: world中是如此二等公民。) – Chap