Skip to content

Latest commit

 

History

History
91 lines (60 loc) · 1.96 KB

CppInvariant.md

File metadata and controls

91 lines (60 loc) · 1.96 KB

 

 

 

 

 

 

An invariant is something that is assumed to be true. For example, the sole integer member variable of a class called 'OddIntegerNumber' can reasonably be assumed to be an odd number.

 

 

 

 

 

 

 

 

 

 

 

 

  1. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 13.7. Advice. page 387: '[11] Let a constructor establish an invariant, and throw if it cannot'
  2. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 13.7. Advice. page 387: '[18] Use "Resource Acquisition Is Initialization" and exception handlers to maintain invariants'
  3. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 13.7. Advice. page 387: '[20] Design your error-handling strategy around invariants'
  4. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 16.4. Advice. page 479: '[3] Use public data (structs) only when it really is just data and no invariant is meaningful for the data members'