liveBook · Manning

What you will learn in 100 C++ Mistakes and How to Avoid Them

by Rich Yonts

Chapter by chapter

Chapter 1: C++: With great power comes great responsibility

1.1 Mistakes · 1.1.1 A quick example · 1.2 Anatomy of a mistake · 1.2.1 Correctness · 1.2.2 Readability · 1.2.3 Effectiveness · 1.2.4 Performance · 1.3 Learning from our mistakes · 1.3.1 Noticing mistakes · 1.3.2 Understanding mistakes · 1.3.3 Fixing mistakes · 1.3.4 Learning from mistakes · 1.4 Where we’ll find mistakes · 1.4.1 Class design · 1.4.2 Program implementation · 1.4.3 Library problems · 1.4.4 Modern C++ · 1.4.5 Old standards and usage · 1.4.6 Lost expertise and misguided training · 1.5 A word about organization · 1.6 Summary

What you learn in chapter 1 →

Chapter 2: Better modern C++: Classes and types

2.1 Mistake 1: Failing to use move semantics · 2.2 Mistake 2: Using empty exception specifications · 2.3 Mistake 3: Not using override on derived virtual functions · 2.4 Mistake 4: Writing simple or hiding unwanted supplied class members · 2.5 Mistake 5: Not using in-class initializers · 2.6 Mistake 6: Overusing index-based loops · 2.7 Mistake 7: Failing to use nullptr · 2.8 Mistake 8: Not using unique_ptrs for exclusive ownership · 2.9 Mistake 9: Not using shared_ptrs for shared ownership

What you learn in chapter 2 →

Chapter 3: Better modern C++: General programming

3.1 Mistake 10: Failing to use if with initialization · 3.2 Mistake 11: Not using type inference for variables · 3.3 Mistake 12: Using typedef · 3.4 Mistake 13: Writing common algorithms · 3.5 Mistake 14: Not using uniform initialization · 3.6 Mistake 15: Failing to use emplacement · 3.7 Mistake 16: Failing to use tuples · 3.8 Mistake 17: Not using structured binding

What you learn in chapter 3 →

Chapter 4: Better modern C++: Additional topics

4.1 Mistake 18: Not using variadic templates · 4.2 Mistake 19: Using global namespace enums · 4.3 Mistake 20: Not using new formatting functionality · 4.4 Mistake 21: Not using ranges with containers · 4.5 Mistake 22: Writing nonportable filesystem code · 4.6 Mistake 23: Writing excessive standalone functions · 4.7 Mistake 24: Using awkward constants · 4.8 Mistake 25: Writing pattern-matching code

What you learn in chapter 4 →

Chapter 5: C idioms

5.1 Mistake 26: Always declaring variables at the top of a function · 5.2 Mistake 27: Depending on macros · 5.3 Mistake 28: Misunderstanding NULL · 5.4 Mistake 29: Accessing disk files using FILE · 5.5 Mistake 30: Using integers for Boolean values · 5.6 Mistake 31: Using C-style casts · 5.7 Mistake 32: Converting text with atoi · 5.8 Mistake 33: Using C-style strings · 5.9 Mistake 34: Calling the exit function · 5.10 Mistake 35: Preferring arrays to vectors

What you learn in chapter 5 →

Chapter 6: Better premodern C++

6.1 Mistake 36: Input and output using scanf and printf · 6.2 Mistake 37: Overusing endl · 6.3 Mistake 38: Dynamic allocation with malloc and free · 6.4 Mistake 39: Using unions for type conversion · 6.5 Mistake 40: Using varargs for variable parameter lists · 6.6 Mistake 41: Incorrect class initialization order · 6.7 Mistake 42: Adding nonvalue types to containers · 6.8 Mistake 43: Favoring indexes over iterators

What you learn in chapter 6 →

Chapter 7: Establishing the class invariant

7.1 Class invariants enforce proper class design · 7.1.1 Interpretation · 7.1.2 Set of operations · 7.1.3 Range of values · 7.1.4 Memory mechanics · 7.1.5 Performance implications · 7.2 Mistakes in class design · 7.2.1 The class invariant · 7.2.2 Establishing the class invariant · 7.3 Mistake 44: Failing to maintain the class invariant · 7.4 Mistake 45: Not thinking of classes as data types · 7.5 Mistake 46: Not establishing a basis for methods · 7.6 Mistake 47: Failing to code the big 3 · 7.7 Mistake 48: Using inheritance just for code reuse · 7.8 Mistake 49: Overusing default constructors · 7.9 Mistake 50: Failing to maintain the is-a relationship

What you learn in chapter 7 →

Chapter 8: Maintaining the class invariant

8.1 Maintaining the class invariant · 8.2 Mistake 51: Writing nonessential accessors · 8.3 Mistake 52: Providing trivial mutators · 8.4 Mistake 53: Overusing protected instance variables · 8.5 Mistake 54: Mistaking operator= and copy constructor semantics · 8.6 Mistake 55: Misunderstanding shallow and deep copy semantics · 8.7 Mistake 56: Failing to call base class operators · 8.8 Mistake 57: Failing to use virtual destructors in polymorphic base classes · 8.9 Mistake 58: Calling virtual functions in constructors and destructors · 8.10 Mistake 59: Attempting to use polymorphic array elements · 8.11 Mistake 60: Failing to initialize all instance variables

What you learn in chapter 8 →

Chapter 9: Class operations

9.1 Mistake 61: Misunderstanding variable shadowing · 9.2 Mistake 62: Allowing duplication of unique objects · 9.3 Mistake 63: Not coding for return value optimization · 9.4 Mistake 64: Not returning a reference from copy assignment operators · 9.5 Mistake 65: Forgetting to handle self-assignment · 9.6 Mistake 66: Misunderstanding prefix and postfix forms · 9.7 Mistake 67: Misleading implicit conversion operators · 9.8 Mistake 68: Overusing implicit conversion constructors · 9.9 Mistake 69: Focusing too much on standalone operators · 9.10 Mistake 70: Failing to mark nonmutating methods constant · 9.11 Mistake 71: Not properly marking class methods static · 9.12 Mistake 72: Incorrectly choosing between member and nonmember functions · 9.13 Mistake 73: Incorrectly returning strings from accessor methods

What you learn in chapter 9 →

Chapter 10: Exceptions and resources

10.1 Using exceptions · 10.1.1 Affirmation: Intermixed control and recovery paths · 10.1.2 Objection: Confusing exception handling with normal error handling · 10.1.3 Objection: Difficulty retrofitting exception handling · 10.1.4 Affirmation: Ambiguous values · 10.1.5 Affirmation: Ambiguous data types · 10.1.6 Affirmation: Enforcing error handling · 10.1.7 Objection: Providing recovery handlers · 10.1.8 Affirmation: Transforming failure types · 10.1.9 Affirmation: Separation of concerns · 10.1.10 Objection: Encouraging upfront design · 10.2 Mistake 74: Not throwing exceptions from constructors · 10.3 Mistake 75: Throwing exceptions from destructors · 10.4 Mistake 76: Allowing resource leaks when using exceptions · 10.5 Mistake 77: Failing to use the RAII pattern · 10.6 Mistake 78: Using raw pointers to resources · 10.7 Mistake 79: Mixing new and delete forms · 10.8 Mistake 80: Trusting exception specifications · 10.9 Mistake 81: Failing to throw by value and catch by reference

What you learn in chapter 10 →

Chapter 11: Functions and coding

11.1 Design considerations · 11.2 Mistake 82: Using overloaded functions instead of parameter defaulting · 11.3 Mistake 83: Failing to use assertions · 11.4 Mistake 84: Returning pointers or references to local objects · 11.5 Mistake 85: Using output parameters · 11.6 Mistake 86: Incorrect use of parameter types · 11.7 Mistake 87: Depending on parameter evaluation order · 11.8 Mistake 88: Passing excessive parameters · 11.9 Mistake 89: Overly long functions with multiple behaviors · 11.10 Mistake 90: Overly responsible functions

What you learn in chapter 11 →

Chapter 12: General coding

12.1 Mistake 91: Improperly handling division by zero · 12.2 Mistake 92: Incorrectly using the continue keyword in loops · 12.3 Mistake 93: Failing to set deleted pointers to NULL · 12.4 Mistake 94: Failing to return directly computed Boolean values · 12.5 Mistake 95: Underusing expressions · 12.6 Mistake 96: Using extraneous else keywords · 12.7 Mistake 97: Not using helper functions · 12.8 Mistake 98: Wrongly comparing floating-point values · 12.9 Mistake 99: Floating-point to integer assignment · 12.10 Mistake 100: Ignoring compiler warnings

What you learn in chapter 12 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.