Skip to content

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

@tira-misu

Description

@tira-misu

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions