Quote:
Now, I'm completely self taught, and I'm well aware I don't do everything "by the book", so people will probably disagree with some of these, but just from personal experience
- initialise in the constructor, free in the destructor
- always make sure pointers are initilised (set to NULL if not used right away)
this means no "dangling" pointers, and any automatic free'ing done by destructors won't fail
- always assert not null before dereference - this protects against seg-faults if something has gone wrong with the allocation
- once free'd, re-set pointer to null (while not usually necessary, it's useful if you do need to allocate and free member pointers outside of con/de/structors)
Good advice.