Closed stachurr closed 1 year ago
This issue does not occur when using std::string and asString()...
Ah. This is a std::map
usage error, not a JsonCpp problem.
The const char*
key is a pointer type, not a string type. The std::map
is going to use pointer operator <
for the lookup, and doesn't consider the pointee at all. So that val.asCString()
pointer is indeed not in the map, which is being correctly reported by the exception.
I have a map of
const char*
's toMyFunc_t
's that I'm using to look up the function associated with the given string. When I try to access this map using the result fromJson::Value::asCString()
anstd::out_of_range
exception is thrown, even though it is equivalent to theconst char*
(as verified withstrcmp
).I hoped that assigning the result like
const char *str = val.asCString()
would solve the problem, but the issue persists.Here exists the bare minimum code required to provide context:
Running the following code works as expected and does not raise any errors:
However, when I try to use
Json::Value::asCString()
, an out of range exception is raised:I expected the function pointer to be returned, but this is not the case.