But wouldn't that have been a compiler issue? Not solving the actual runtime issue?
Anyway, I wrote the following before seeing your latest post:
_____________________________________________
You're doing some weird copy-pasting, decreasing the chances of us being able to build the same thing you're building. You accidentally left out the protected/private fields of other classes. e.g.
part in that latest link.
You're defining the following in your .cpp:
1 2 3
|
std::map<const std::string, const Value*> JSONObject::getValues() {
return this->values;
}
| |
But in the hpp it's:
std::map<std::string, const Value*> getValues();
(One has a const the other one doesn't. It's kind of dumb that this matters, but it makes my compiler barf.)
I just removed the const from the std::string part of the template type to make it compile.
_____________________________________________
Now, that compiling is out of the way...
You have some... potentially undefined behavior.
I say "potentially" because I didn't bother examining every possibility, but there are warnings like:
libjson.cpp:201:17: warning: 'elementValue' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (elementValue) {
^~ |
Interestingly, these warnings only show up when I build with optimizations enabled.
See, the problem is, it might theoretically be possible that none of the if statements between lines 181 to 197 are entered.
If that's the case, then elementValue is not initialized correctly.
Which eventually makes it possible that you're deleting or manipulating a junk pointer.