C++ / a working model

BOOK / SOURCE & READING RECORD

More Effective C++: 35 New Ways to Improve Your Programs and Designs

Scott Meyers

Original first edition, 1995/1996; additional accessed Chinese composite PDF credits ZHC for Items1–28 and WQ for Items29–35; exact published translation edition unverified

READING EVIDENCE / Full text read

More Effective C++: 35 New Ways to Improve Your Programs and Designs

Have fully read all technical items Items 1–35 of the public 267-page Chinese composite PDF (PDF pages 11–240), the recommended reading and auto_ptr appendix (pages 240–247), and two additional articles (pages 247–267), and have directly verified all 31 embedded figures in the main text as well as the notation notes on page 9 by inspecting the figures. “full” refers only to all substantial chapters of this public Chinese text, not page-by-page verification of the English original or a commercial Chinese edition: the commercial translation’s edition is unverified; the first 4–5 pages of Chinese appear as boxes in both the source PDF and the images, were not recovered, and are not counted as technical main text. The publisher’s English Item 33 was also read for cross-checking; historical translator notes and code errors should not be treated as C++20 rules.

Edition, actual reading range, and original sources →

Sources

Base-class assignment is not polymorphic copying

Full English publisher Item 33; Chinese composite PDF Items 9–10 (pages 41–54), 33 (pages 219–229)

After fully reading Item 33, what is worth retaining is the method of reviewing the interface, not adding an abstract layer whenever inheritance is seen. If the base class exposes assignment, callers can update only part of the object through a base-class reference; if assignment is made virtual, one must also handle the problem of the two ends having different dynamic types. A reasonable interface should first state whether copying means replacing a value, modifying an existing entity, or producing a new entity. Read-only polymorphic services often do not need public base-class assignment at all; restricting it to the protected region can shrink the error space, while concrete leaves can still have normal value semantics. After C++11 one can use final and type traits to make these intents explicit, but final cannot be treated as a substitute for protecting base-class assignment. The book’s auto_ptr is a historical facility and should not be brought into new C++20 code.

Retain the problem analysis; replace outdated implementation premises

Chinese composite PDF Items 14–15 (pages 67–74), 20 (pages 90–94), 29–30 (pages 152–193)

After reading the full set of Chinese items, the most important thing to prevent is mistaking historical implementation capabilities for today’s language limitations. The reference-counting and proxy discussion reveals that after a borrowed pointer escapes, shared writes destroy value semantics; this remains a good question when reviewing custom data structures, but one should not conclude from it that modern std::string uses copy-on-write. The temporary-objects chapter correctly emphasizes not returning local references, yet treats return-value optimization as an optional compiler capability; since C++17 certain prvalue returns construct the result directly, while named local returns remain a different case. The exception chapter’s dynamic exception specifications, old measurements of exception overhead on the normal path, and workarounds for lack of explicit are also suitable only as historical material. First identify the invariants being maintained, then choose current standard facilities; that is more reliable than reproducing old code.

Related fundamentals

Deep copy, shallow copy, and the Rule of Zero / FiveAbstract class and pure virtual function definitionsStatic and Dynamic Polymorphism, Slicing, and RTTIRAII: Give Cleanup Responsibility to Objects

Original practice →