listings-Chap20-README.md
Listings of Chap20.docx
This is linked summary of the listings. You can also view it on one page.
- GodboltId:4536hxvEK
- Book: lst-0003-book.cpp
- Godbolt: lst-0003-godb.cpp, https://godbolt.org/z/4536hxvEK
- Listing 20.1: Pointers can be assigned new addresses during their lifetime.
- Book: lst-0004-book.cpp
- Godbolt: lst-0004-godb.cpp, https://godbolt.org/z/7GEWYeoc9
- Listing 20.2: Returning by value can create a copy.
- Book: lst-0007-book.cpp
- Listing 20.3: Returning as a pointer only copies the pointer, not the object.
- Book: lst-0008-book.cpp
- Listing 21.4: In the following examples, I use Image as a class for which I want a pointer.
- Book: lst-0010-book.cpp
- Godbolt: lst-0010-godb.cpp, https://godbolt.org/z/ehhGPjabz
- Listing 20.4: unique_ptr as data field, return value, and local variable.
- Book: lst-0011-book.cpp
- Godbolt: lst-0011-godb.cpp, https://godbolt.org/z/aTTejrnWE
- Listing 20.5: A game board with various objects.
- Book: lst-0013-book.cpp
- Godbolt: lst-0013-godb.cpp, https://godbolt.org/z/4KP91z1bq
- Listing 20.6: When a raw pointer owns an object, the potential errors are often hard to detect.
- Book: lst-0016-book.cpp
- Godbolt: lst-0016-godb.cpp, https://godbolt.org/z/Y4sMdzde8
- Listing 20.7: “primes” contains pointers to another container.
- Book: lst-0018-book.cpp
- Godbolt: lst-0018-godb.cpp, https://godbolt.org/z/W4W61h4Kv
- Listing 20.8: Do not return addresses of function-local objects.
- Book: lst-0021-book.cpp
- Listing 20.9: With raw pointers pointing to a C-array, you can perform arithmetic.
- Book: lst-0026-book.cpp
- Godbolt: lst-0026-godb.cpp, https://godbolt.org/z/a5b6qMo9h
- Listing 20.10: C-arrays decay to raw pointers as parameters.
- Book: lst-0030-book.cpp
- Godbolt: lst-0030-godb.cpp, https://godbolt.org/z/1qx16Gr61
- Listing 20.11: “unique_ptr” works with the dynamic C-array.
- Book: lst-0034-book.cpp
- Godbolt: lst-0034-godb.cpp, https://godbolt.org/z/h3q839x8r
- GodboltId:s6sss481E
- Book: lst-0038-book.cpp
- Godbolt: lst-0038-godb.cpp, https://godbolt.org/z/s6sss481E
- Listing 20.12: With “string”, you often don’t even notice that text literals are “const char[]”.
- Book: lst-0039-book.cpp
- Godbolt: lst-0039-godb.cpp, https://godbolt.org/z/oKsz7d55T
- Listing 20.13: Retrieve iterators with “begin” and “end”.
- Book: lst-0040-book.cpp
- Godbolt: lst-0040-godb.cpp, https://godbolt.org/z/4nqz4ed4W
- Listing 20.14: You can use raw pointers like iterators.
- Book: lst-0041-book.cpp
- Godbolt: lst-0041-godb.cpp, https://godbolt.org/z/zsqKz76cj
- Listing 20.15: Is it worth saving the release of memory?
- Book: lst-0042-book.cpp
- Godbolt: lst-0042-godb.cpp, https://godbolt.org/z/xE1TWx1ve