Tuesday, December 11, 2007

excerpt of effective c++

1. rules for effective c++ programming vary, depending on the part of c++ you are using (c, c++, template, STL)

2. For simple constants prefer const objcts or enums to $defines (enum hack)

3. For function-like macros, prefer inline functions to #defines (which has side-effect)

4. Declaring soemthing const helps compilers detect usage erros. const can be applied to objects at any scope, to function parameters and return types, and to member functions as a whole

5. Compilers enforce bitwise constness, but you should program using conceptual constness (e.g., use of mutable)

6. When const and non-const member functions have essentially identical implementations, code duplication can be avoided by having the non-const version call the const version

7. Manually initialize objects of built-in type, because C++ only sometimes initializes them itself

8. In a constructor, prefer use of the member initialization list to assignment inside the body of constructor. List data members in the initialization list in the same order they are declared in the class.

9. Avoid initilization order problems across translation units by replacing non-local static objects with local static objects

0 Comments:

Post a Comment

<< Home