(ref.doc)cr59-20

Next cr59-38 Prev: cr59-14 Up: cppR 5/9

pp 20-22
C++ Traps and pitfalls
How to avoid dangling pointers
by Andrew Koenig

int* p = new int;
delete p;
*p = 42;

Indeed, the implementation is permitted to change the value of p
itself to make it easier to detect the error.

If you don't have such a class [flexible array] available, write one.

[...] local variables are usually destroyed in reverse order of
creation.

When giving a value to a local pointer variable, make sure it's the
address of something that existed when the pointer was created.


automatically generated by info2www version 1.2.2.8