1. Accustoming Yourself to C++

10May - by qkim0x01 - 2 - In Private Notes

Book review of Effective C++ by Scott Meyers

1. Accustoming yourself to C++

Item 1: View C++ As a Federation of Language
Things to Remember
  • Rules for effective C++ programming vary, depending on the part of c++ you are using

Item2: Prefer consts, enums, and inlines to #define
Things to Remember
  • For simple constants, prefer const objects or enums to #defines
  • For function-like macros, prefer inline functions to #define

Item 3: Use const whenever possible
Things to Remember
  • Declaring something const helps compilers detect usage errors.
    • const can be applied to objects at any scope, to function parameters and return types, and to member functions as a whole
  • Compilers enforce bitwise constness, but you should program using logical constness
  • 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

Item 4: Make sure that objects are initialized before they’re used
Things to Remember
  • Manually initialize objects of built-int type
    • because C++ only sometimes initializes them itself
  • In a constructor, prefer use of the member initialization list to assignment inside the body of the constructor
  • Void initialization order problems across translation units by replacing non-local static objects with local static objects

2 thoughts on “1. Accustoming Yourself to C++”

Leave a Reply

Your email address will not be published. Required fields are marked *