flatbuffers
flatbuffers copied to clipboard
[cpp] LookupByKey did not work for char* (works only for const char* or std::string)
If you have a key in a struct and you try to use LookupByKey() with a char* (without const) the wrong function is called:
int KeyCompareWithValue(const char *_address) const {
return strcmp(address()->c_str(), _address);
}
template<typename StringType>
int KeyCompareWithValue(const StringType& _address) const {
if (address()->c_str() < _address) return -1;
if (_address < address()->c_str()) return 1;
return 0;
}
With char* it uses the second one, because 'KeyCompareWithValue(const char*& _address)' is not implemented. So the compare failes and the value will not be found.