|
|
Knowledge Base/CPP/More Effective CPP
From The Thalesians
This is essentially the table of contents of Scott Meyers' book More Effective C++. The same table of contents is available on Amazon.com, but not on Amazon.co.uk (check out the "Look Inside" feature). In my 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. I would read the book.
Contents |
[edit]
Basics
- Distinguish between pointers and references
- Prefer C++-style casts
- Never treat arrays polymorphically
- Avoid gratuitious default constructors
[edit]
Operators
- Be wary of user-defined conversion functions
- Distinguish between prefix and postfix forms of increment and decrement operators
- Never overload &&, ||, or ,
- Understand the different meanings of new and delete
[edit]
Resource management
- Use destructors to prevent resource leaks
- Prevent resource leaks in constructors
- Prevent exceptions from leaving destructors
- Understand how throwing an exception differs from passing a parameter or calling a virtual function
- Catch exceptions by reference
- Use exception specifications judiciously
- Understand the costs of exception handling
[edit]
Efficiency
- Remember the 80-20 rule
- Consider using lazy evaluation
- Ammortise the cost of expected computations
- Understand the origin of temporary objects
- Facilitate the return value optimisation
- Overload to avoid implicit type conversions
- Consider using op= instead of stand-alone op
- Consider alternative libraries
- Understand the costs of virtual functions, multiple inheritance, virtual base classes, and RTTI
[edit]
Techniques
- Virtualising constructors and non-member functions
- Limiting the number of objects of a class
- Requiring or prohibiting heap-based objects
- Smart pointers
- Reference counting
- Proxy classes
- Making functions virtual with respect to more than one object
[edit]
Miscellany
- Program in the future tense
- Make non-leaf classes abstract
- Understand how to combine C++ and C in the same program
- Familiarise yourself with the language standard
