You need to be explicit about the argument to the constructor:
JsonValue stringItem(std::string("test"));
What is happening is that you are getting an implicit conversion from const char*
to bool
, because this is a conversion between built-in types, and a better match than the conversion from const char*
to std::string
, which is a conversion involving a built-in type.
Alternatively, you can add a constructor that takes const char*
and stores a string internally. This is a better option because it avoids the easy to make error you encountered:
JsonValue::JsonValue(const char* astr)
: mType(Type::String) {
mData.str = new std::string(astr);
}
Note that on the surface these seems to be no reason to store a dynamically allocated string. This probably adds unnecessary complications.