3 ms·
Right. But an object being in an inconsistent/invalid state can have more serious consequences in C++ than in other languages, due to the weak typing and manual
by layer8 4y ago
Right. But an object being in an inconsistent/invalid state can have more serious consequences in C++ than in other languages, due to the weak typing and manual-by-default memory management. In other languages, the programs may be just as incorrect, but the consequences, when the fault arises, tend to be less fatal. Of course, such a fault can in principle still lead to lost or corrupted data, but that tends to be lesa visible than a segfault.
- kllrnohj 4y agoThat'd only be the case if you're not using things like unique_ptr / shared_ptr. Or if you have a really funky entangled ownership model such that a split-copy ends up leaving you in a confused ownership model such that the destructor doesn't do the right thing. And you didn't catch the exception to patch that up before propagating it. That seems like a bit of a stretch to come up with hitting such a scenario, and if you do it doesn't seem like a copy & swap idiom is really the solution.