flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

[cpp] LookupByKey did not work for char* (works only for const char* or std::string)

Open tira-misu opened this issue 10 months ago • 0 comments

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.

tira-misu avatar Mar 17 '25 10:03 tira-misu