3 ms·
Sure, but it’s not enough. You can forget the virtual destructor. Maybe the language is excused because it’s only a leak. You could mess up the what() functio
by amluto 4y ago
Sure, but it’s not enough.
You can forget the virtual destructor. Maybe the language is excused because it’s only a leak.
You could mess up the what() functions. (It’s not locally obvious that it’s correct in this code.) std::exception is fundamentally dangerous. Rust can get away with safely returning references like that because the lifetime is part of the function’s signature. C++, even modern C++, can’t.
Even the iterative example is only a bit safe. You can’t walk off the end by going one too far, but you can certainly mess up by invalidating the iterator in the loop body.