I haven’t written C++ in a while, so I’m a bit rusty. If I have a class like this:
class JsonType{
protected:
map<string, JsonType>* objects;
}
and a class that inherits from that:
class JsonObject : public JsonType{
public:
JsonObject(){
this->objects = new map<string, JsonObject>();
}
}
why would I be getting a compiler error cannot convert...JsonObject...to...JsonType? Shouldn’t that be legal, since JsonObject is a JsonType?
You can add JsonObject objects to the map, but the types do not match for initialization.
Edit: You have to initialize it as:
But if you have either objects:
or
or
You can add any of these objects to the map initialized as above.