listings-Chap12-README.md
Listings of Chap12.docx
This is linked summary of the listings. You can also view it on one page.
- Listing 12.1: Creating your own data type with “struct”.
- Book: lst-0001-book.cpp
- Godbolt: lst-0001-godb.cpp, https://godbolt.org/z/8YqoTEx58
- Listing 12.2: The declaration of a class initially only mentions its name, while the definition contains all its elements.
- Book: lst-0002-book.cpp
- Godbolt: lst-0002-godb.cpp, https://godbolt.org/z/zPbK16zWE
- Listing 12.3: With designated initializers, you specify the elements to be set.
- Book: lst-0005-book.cpp
- Godbolt: lst-0005-godb.cpp, https://godbolt.org/z/K8WePajvM
- GodboltId:rrjPorT1o
- Book: lst-0006-book.cpp
- Godbolt: lst-0006-godb.cpp, https://godbolt.org/z/rrjPorT1o
- GodboltId:ME76bfbWa
- Book: lst-0007-book.cpp
- Godbolt: lst-0007-godb.cpp, https://godbolt.org/z/ME76bfbWa
- Listing 12.4: Here, specifying Person in the return is necessary.
- Book: lst-0010-book.cpp
- Godbolt: lst-0010-godb.cpp, https://godbolt.org/z/jer44aWs9
- Listing 12.5: Methods bundle data and behavior together.
- Book: lst-0011-book.cpp
- Godbolt: lst-0011-godb.cpp, https://godbolt.org/z/5T1Er36P7
- Listing 12.6: The “greeting()” method uses fields; via “this”, it always refers to the field belonging to the called object.
- Book: lst-0012-book.cpp
- Listing 12.7: How to separate methods and data from each other.
- Book: lst-0014-book.cpp
- GodboltId:hEvqWqqc6
- Book: lst-0015-book.cpp
- Godbolt: lst-0015-godb.cpp, https://godbolt.org/z/hEvqWqqc6
- Listing 12.8: “print” takes a stream as an argument.
- Book: lst-0018-book.cpp
- Godbolt: lst-0018-godb.cpp, https://godbolt.org/z/bz6n3Pjrv
- Listing 12.9: You can overload the standard operator for output.
- Book: lst-0019-book.cpp
- Listing 12.10: The output with << is achieved by overloading a free function.
- Book: lst-0021-book.cpp
- Godbolt: lst-0021-godb.cpp, https://godbolt.org/z/a7q5xsWGj
- Listing 12.11: Methods can also be defined inline.
- Book: lst-0022-book.cpp
- Godbolt: lst-0022-godb.cpp, https://godbolt.org/z/Y3eW1Kh8v
- Listing 12.12: How to define a constructor.
- Book: lst-0027-book.cpp
- Listing 12.13: Multiple constructors are also possible.
- Book: lst-0029-book.cpp
- Godbolt: lst-0029-godb.cpp, https://godbolt.org/z/zndbvh5nK
- Listing 12.14: Member variables can be equipped with default values.
- Book: lst-0030-book.cpp
- Godbolt: lst-0030-godb.cpp, https://godbolt.org/z/Wo8zaq9WW
- Listing 12.15: A constructor can pass part of the initialization to another constructor.
- Book: lst-0031-book.cpp
- Godbolt: lst-0031-godb.cpp, https://godbolt.org/z/8h93f64Yj
- Listing 12.16: A constructor can also be overloaded with default parameters.
- Book: lst-0032-book.cpp
- Godbolt: lst-0032-godb.cpp, https://godbolt.org/z/Gfrd5cceG
- Listing 12.17: A constructor with all preset arguments becomes the default constructor.
- Book: lst-0034-book.cpp
- Godbolt: lst-0034-godb.cpp, https://godbolt.org/z/1fE15Kf39
- Listing 12.18: Do not call an initializing method in the constructor body.
- Book: lst-0035-book.cpp
- Godbolt: lst-0035-godb.cpp, https://godbolt.org/z/dzjaf6nbb
- Listing 12.19: External access to the data fields of a type.
- Book: lst-0037-book.cpp
- Listing 12.20: Divide a type into multiple sections with “public” and “private”.
- Book: lst-0038-book.cpp
- Godbolt: lst-0038-godb.cpp, https://godbolt.org/z/4MzxaevKa
- Listing 12.21: A “class” starts with private visibility.
- Book: lst-0039-book.cpp
- Godbolt: lst-0039-godb.cpp, https://godbolt.org/z/MYzsqfqdo
- Listing 12.22: Parts of the data are private.
- Book: lst-0040-book.cpp
- Godbolt: lst-0040-godb.cpp, https://godbolt.org/z/Pr76Y55P4
- Listing 12.23: With “= default”, you let the compiler generate code.
- Book: lst-0041-book.cpp
- Godbolt: lst-0041-godb.cpp, https://godbolt.org/z/PaG9nTs7s
- Listing 12.24: Custom data types can protect against errors. This is the first step toward that.
- Book: lst-0042-book.cpp
- Godbolt: lst-0042-godb.cpp, https://godbolt.org/z/aGd56xzsT
- Listing 12.25: If all “return” statements return the same variable, the compiler can always avoid a copy.
- Book: lst-0051-book.cpp
- Godbolt: lst-0051-godb.cpp, https://godbolt.org/z/T7afh4vxz
- Listing 12.26: With “explicit”, you prevent automatic type conversion.
- Book: lst-0060-book.cpp
- Listing 12.27: “Year” no longer has “value()” and requires other methods.
- Book: lst-0070-book.cpp
- Godbolt: lst-0070-godb.cpp, https://godbolt.org/z/EPz4Kd6jP
- Listing 12.28: If “advance” returns the object itself, then you can call another method afterward.
- Book: lst-0071-book.cpp
- Listing 12.29: A fluent programming interface sometimes allows for clear code.
- Book: lst-0072-book.cpp
- Listing 12.30: The internal type “int” has become part of the class interface.
- Book: lst-0073-book.cpp
- Godbolt: lst-0073-godb.cpp, https://godbolt.org/z/hbsbMsGr1
- Listing 12.31: With “using”, you can introduce type aliases that make it easier to maintain interfaces than with the types themselves.
- Book: lst-0074-book.cpp
- Godbolt: lst-0074-godb.cpp, https://godbolt.org/z/EYjo8E8Gn
- Listing 12.32: The standard library also contains many useful type aliases.
- Book: lst-0075-book.cpp
- Godbolt: lst-0075-godb.cpp, https://godbolt.org/z/zdMfoa7Yj
- Listing 12.33: When initializing a variable, the compiler can determine the type.
- Book: lst-0079-book.cpp
- Godbolt: lst-0079-godb.cpp, https://godbolt.org/z/Wh71cf7j1
- Listing 12.34: Type deduction with “auto” can be further restricted using a concept.
- Book: lst-0080-book.cpp
- Godbolt: lst-0080-godb.cpp, https://godbolt.org/z/qzWchWoeK
- Listing 12.35: When you enrich “auto” with &, you get a modifiable reference.
- Book: lst-0081-book.cpp
- Godbolt: lst-0081-godb.cpp, https://godbolt.org/z/ro6fdsvT9
- Listing 12.36: To pack a custom data type into a “vector”, it does not need to meet many requirements.
- Book: lst-0085-book.cpp
- Godbolt: lst-0085-godb.cpp, https://godbolt.org/z/8ejPs6zr6
- Listing 12.37: For a “set” of a custom data type, you need to override “operator<”.
- Book: lst-0086-book.cpp
- Godbolt: lst-0086-godb.cpp, https://godbolt.org/z/Yhzqo6dxT
- GodboltId:TdEnhKxGK
- Book: lst-0087-book.cpp
- Godbolt: lst-0087-godb.cpp, https://godbolt.org/z/TdEnhKxGK