Dec 13, 2008 at 6:14pm UTC jsmith (5804)

IIRC 0 was OK to use as the starting for() loop index. but the SOME_CONSTANT_MAX, absolutely. 1 - forget it. Better use a descriptive #define.



These aren't exactly often asked questions, and perhaps aren't even beginner guidelines, but nonetheless IMHO beginners should learn to do the following from the start:



9. Write constructors. Constructors that can take exactly one argument should be explicit, unless it is the copy constructor.



10. Only write a copy constructor if you need to take deep copies or do weird things. In which case also write the assignment operator.



11. If an assignment operator throws, it must leave the "assigned to" object in a known state.



12. Only write a destructor if absolutely necessary (ie, to free owned memory).



12a. Consider using smart pointers or auto_ptrs in place of raw pointers so that memory leaks are less likely (in which case you don't need a destructor).



13. Consider writing operator<< for all value classes, even if just for debugging purposes.



14. Use const correctly.







