English
Topic 7. Classes and objects: data members, member functions, constructors, destructors, and encapsulation
Goal: learn to apply the concepts of the topic “Classes and objects: data members, member functions, constructors, destructors, and encapsulation” in console projects; justify invariants and the contracts of operations; test both ordinary and edge cases.
Lecture contents
- Class, invariant, and constructors — State, behavior, and the class invariant · Constructors and the member initializer list
- Composition and object lifetime — Composition and splitting code into files · Object lifetime and the destructor
- const, static, and aggregates — Constness, this, and observing state · Static members and nested types · Aggregates and designated initialization
- Designing and testing a class — Designing a minimal interface · Diagnosing and checking invariants · Scenario walkthrough: a seat reservation class
- Case studies and common mistakes — Reference lifetime, member objects, and failed construction · Checking an interface with a contract table · The boundary between a constructor and user input · When an accessor grants too much freedom · A review case: an initialization error