Personal tools
User menu

Knowledge Base/CPP/Effective CPP

From Thalesians

Jump to: navigation, search

This is essentially the table of contents of Scott Meyers' book Effective C++, Third Edition. The same table of contents is available on, but not on (check out the "Look Inside" feature). In our view, every serious C++ programmer should read Scott's book. Of course, you need to read the entire book. The chapter titles will only make sense if you have read it. If you haven't read it and the titles still make sense, you are still missing a lot. We would read the entire book.


Accustoming yourself to C++

  1. View C++ as a federation of languages
  2. Prefer consts, enums, and inlines to #defines
  3. Use const whenever possible
  4. Make sure that objects are initialised before they're used

Constructors, destructors, and assignment operators

  1. Know what functions C++ silently writes and calls
  2. Explicitly disallow the use of compiler-generated functions you do not want
  3. Declare destructors virtual in polymorphic base classes
  4. Prevent exceptions from leaving destructors
  5. Never call virtual functions during construction or destruction
  6. Have assignment operators return a reference to *this
  7. Handle assignment to self in operator=
  8. Copy all parts of an object

Resource management

  1. Use objects to manage resources
  2. Think carefully about copying behaviour in resource-managing classes
  3. Provide access to raw resources in resource-managing classes
  4. Use the same form in corresponding uses of new and delete
  5. Store newed objects in smart pointers in standalone statements

Designs and declarations

  1. Make interfaces easy to use correctly and hard to use incorrectly
  2. Treat class design as type design
  3. Prefer pass-by-reference-to-const to pass-by-value
  4. Don't try to return a reference when you must return an object
  5. Declare data members private
  6. Prefer non-member non-friend functions to member functions
  7. Declare non-member functions when type conversions should apply to all parameters
  8. Consider support for a non-throwing swap


  1. Postpone variable definitions as long as possible
  2. Minimise casting
  3. Avoid returning "handles" to object internals
  4. Strive for exception-safe code
  5. Understand the ins and outs of inlining
  6. Minimise compilation dependencies between files

Inheritance and object-oriented design

  1. Make sure public inheritance models "is-a"
  2. Avoid hiding inherited names
  3. Differentiate between inheritance of interface and inheritance of implementation
  4. Consider alternatives to virtual functions
  5. Never redefine an inherited non-virtual function
  6. Never redefine a function's inherited default parameter value
  7. Model "has-a" or "is-implemented-in-terms-of" through composition
  8. Use private inheritance judiciously
  9. Use multiple inheritance judiciously

Templates and generic programming

  1. Understand implicit interfaces and compile-time polymorphism
  2. Understand the two meanings of typename
  3. Know how to access names in templetised base classes
  4. Factor parameter-independent code out of templates
  5. Use member function templates to accept "all compatible types"
  6. Define non-member functions inside templates when type conversions are desired
  7. Use traits classes for information about types
  8. Be aware of template metaprogramming

Customising new and delete

  1. Understand the behaviour of the new-handler
  2. Understand when it makes sense to replace new and delete
  3. Adhere to convention when writing new and delete
  4. Write placement delete if you write placement new


  1. Pay attention to compiler warnings
  2. Familiarise yourself with the standard library, including TR1
  3. Familiarise yourself with Boost
  • This page was last modified on 13 January 2009, at 18:48.
  • This page has been accessed 13,295 times.