3 ms·
A(int sz) { sz_ = sz; v = new B[sz_]; } ~A() { delete v; } Surely if the allocation of v fails, the destructor will delete some wrong memory pointed at by an
by willvarfar 15y ago
A(int sz) { sz_ = sz; v = new B[sz_]; }
~A() { delete v; }
Surely if the allocation of v fails, the destructor will delete some wrong memory pointed at by an unintialised v?
The pain of not using initialiser lists?
- DerekL 15y agoNo. If the allocation fails, it throws an exception, and the destructor isn't called.