5
« on: May 13, 2008, 03:05:36 PM »
Buffer overruns, dangling pointers, uninitialised variables... one reason to use C++ is that you don't need to have any of these things (maybe the occasional use of pointers for efficiency, but try to avoid it).
Always use vectors instead of arrays (you can make an exception for dungeon maps).
Always access objects in vectors using the index (a downside of using arrays is that pointers are dangerous, unlike in C-style arrays, because vectors can reallocate).
Try to use vectors in preference to lists. Lists tempt you to use pointers.
Always initialise variables in the constructor (exceptions can be made for really small classes such as Point, Rect, etc.).
Whatever you do there will still be bugs. Chase them hard when you see them. Sometimes when you have a baffling bug, when you wake up ater a night's sleep you will know the cause.