4 ms·
"Shouldn't throw exceptions in constructors"? Seriously? It's actually strongly recommended to do so. Unlike what this article says, it works just fine: - if y
by loufoque 16y ago
"Shouldn't throw exceptions in constructors"? Seriously?
It's actually strongly recommended to do so.
Unlike what this article says, it works just fine:
- if you throw from the constructor-initializer, it destructs all the members and the base classes that were already initialized,
- if you throw from the constructor body, it destructs all local variables in scope then all members and base classes.
As for not being able to call virtual functions from base classes, there are good reasons why it is not allowed.
About bounds checking, GCC does provide a debug mode with operator[] doing bounds checking.
Local static initialization is thread-safe (see the C++0x standard)
Exception-safety is a serious issue, but solving this problem -- which is fairly easy, just use RAII -- actually leads to better and safer code.