C++20 update: using enum class (which significantly improves the usefulness of enum class).
11 Animation with structs and sprites 11-173
11.1 struct 11-173
11.2 Making a movie with struct and while 11-176
11.3 Sprites 11-182
Examples: bouncing balls; a video aquarium.
C++20 update: designated initializers for structs.
12 Building your own arcade game: input, collisions, and putting it all together 12-188
12.1 Determining input states 12-188
12.2 Events 12-190
12.3 Cooldowns and lifetimes 12-191
12.4 Collisions 12-194
12.5 The big game 12-195
Examples: an arcade game, and the student's own game.
13 Standard I/O and file operations 13-204
13.1 Standard I/O programs in Visual C++ and g++ 13-204
13.2 File I/O (optional) 13-210
Examples: various programs reading/writing text files.
Except for Chapter 21 (virtual functions), this and subsequent chapters use standard console I/O, not the SSDL graphics library.
If used for a course, this chapter likely ends the first semester, so if students are going into a class with a different textbook, they are ready for the console I/O it will certainly require them to know.
14 Character arrays and dynamic memory (pointers) 14-221
14.1 Character arrays 14-221
14.2 Dynamic allocation of arrays. 14-224
14.3 Using the * notation 14-228
Examples: C's string functions, written as examples or offered as exercises; code with new and delete
C++20 updates: array size deduction in new expressions.
15 Classes: the basics 15-232
15.1 Writing classes 15-232
15.2 Constructors 15-235
15.3 const objects, const member functions... 15-239
15.4 ...and const parameters 15-241
15.5 Multiple constructors 15-241
15.6 Default parameters for code reuse 15-244
15.7 Date program (so far) 15-245
Examples: the Date class; the student's own Time class.
16 Classes, continued 16-248
16.1 inline functions for efficiency 16-248
16.2 Access functions 16-249
16.3 static members, inline, and constexpr/constinit 16-250
16.4 Separate compilation and include files 16-252
16.5 Multiple-file projects in Microsoft Visual C++ 16-257
16.7 Multiple-file projects in g++ 16-259
16.8 Final Date program 16-264
Examples: the Date class; the student's own Time class, continued.
C++20 updates: constexpr/consteval member functions; constexpr/constinit data members and their interaction with static.
17 Operators, and destructors 17-268
17.1 The basic string class 17-268
17.2 Destructors 17-270
17.3 == and != operators 17-271
17.3 Other comparison operators, using the spaceship operator 17-271
17.4 Assignment operators and *this 17-273
17.5 Arithmetic operators 17-275
17.6 [] and () operators 17-279
17.7 >> and <<: operators that aren't class members 17-281
17.8 ++ and -- 17-283
17.9 Explicit call to constructor 17-284
17.10 .The final String class 17-285
17.11 #include 17-291
Examples: a String class; the student's own Point or Fraction class.
C++20 updates: implicit != operator; the three-way "spaceship" () operator.
18 Exceptions, recursion, and O notation 18-292
18.1 Exceptions 18-292
18.1 Move constructors and move = (optional) 18-296
18.2 Recursion (optional; used in the next section) 18-300
18.3 Algorithm analysis and O-notation (optional) 18-303
Examples: a Stack class; a factorial function; binary and linear search.
19 Classes, continued: inheritance 19-309
19.1 The basics of inheritance 19-309
19.2 Constructors and destructors 19-312
19.2 Inheritance as a concept 19-312
19.3 An inheritance heirarchy, and public/private inheritance 19-314
19.4 Modules: the modern way to maintain libraries 19-314
Examples: card games.
C++20 update: modules.
20 Template functions and classes 20-335
20.1 Function templates 20-335
20.2 The Vector class 20-338
20.3 Making Vector a template 20-341
20.4 Unusual class templates (optional) 20-345
20.5 #include ^t; 20-346
C++20 updates: concepts; class template argument deduction for aggregates.
21 Multiple inheritance and virtual functions 21-347
21.1 Virtual functions 21-347
21.2 Multiple inheritance 21-357
Example: a Shape class. This chapter uses the SSDL library.
C++20 updates: if it fits with the examples, constexpr virtual functions.
22 Linked lists 22-359
22.1 What lists are and why have them 22-359
22.2 The (default) constructor 22-363
22.3 push_front 22-363
22.4 pop_front 22-365
22.5 The destructor 22-367
22.6 ->: a bit of syntactic sugar 22-367
22.7 A bit more friendly syntax: pointers as conditions 22-367
22.8 The linked list template 22-368
22.9 #include 22-371
Example: the List class.
23 The Standard Template Library (STL) 23-371
23.1 Iterators 23-371
23.2 Getting really lazy: ranges and auto 23-375
23.3 Initializer lists (optional) 23-376
23.4 algorithm (optional) 23-375
Example: an extension of the List class to use iterators.
C++20 updates: initialization statements in range-based for loops (Section 23.2); std::span (23.2); parenthesized initialization of aggregates (23.3); simplified erase*/remove* functions (23.4).
If this is used for a class, the second semester likely ends with Chapter 19 or 20. Remaining chapters are extras for those who want to go further.
24 Building bigger projects 24-377
24.1 Namespaces 24-377
24.2 Conditional compilation 24-378
24.3 Libraries 24-378
25 History 25-382
25.1 SIMULA 67 25-382
25.2 Smalltalk 25-382
25.3 What "object-oriented" is 25-383
25.4 C 25-383
25.5 C++ 25-383
26.6 C++'s evolving standards, C++98 to C++20 25-383
26 Esoterica (recommended) 26-385
26.1 Formatted output (fmt) 26-385
26.2 Command-line arguments 26-387
26.3 static_cast et al 26-389
26.4 Defaulted constructors and = 26-391
26.5 User-defined literals: let C++ handle your units for you 26-393
26.6 Lambda functions for one-time use 26-395
26.7 Sructured bindings: returning multiple values at once 26-398
26.8 Smart pointers 26-400
26.9 Bit twiddling: &, |, and ~ 26-402
C++20 updates: Formatted output; std::make_shared()'s support for arrays (Section 26.8).
27 Esoterica (not so recommended) 27-404
27.1 protected sections 27-404
27.2 Template specialization 27-405
27.3 friends and why you shouldn't have any 27-405
27.4 User-defined conversions 27-408
28 C 28-412
28.1 Compiling C 28-412
28.2 I/O 28-414
28.3 Parameter passing with * 28-421
28.4 Dynamic memory 27-423
Examples: programs using C's stdio functions (printf, sscanf, etc.).
29 Moving on with SDL 29-424
29.1 A basic program in SDL 29-424
29.2 Compling 29-426
29.3 Further resources 29-427
Appendices
A. Setting up SDL and SSDL 427
B. Operators 429
C. ASCII codes 429
D. Escape sequences 430
E. Basic C standard library 432
F. SSDL reference 435
Index 448
References 455
Will Briggs, PhD is a professor of computer science at the University of Lynchburg in Virginia. He has 20+ years of experience teaching C++, 12 of them using earlier drafts of this book, and about as many years teaching other languages including C, LISP, Pascal, PHP, PROLOG, and Python. His primary focus is teaching of late while also active in research in artificial intelligence.
Ready to learn programming with less effort and more fun? Then do it the lazy way! C++20 for Lazy Programmers uses humor and fun to make you actually willing to read and eager to do the projects as you master the popular and powerful C++ language. Along the way it includes many features from the new C++20 standard, such as ranges, spans, format strings, the “spaceship” operator, and concepts (template parameter requirements), and provides brief introductions to modules and coroutines.
With this unique method, you’ll stretch your abilities with a variety of projects, including your own C++ arcade game. You'll construct your own classes, templates, and abstract data types. After reading and using this book you’ll be ready to build real-world C++ applications and game projects on your own.
You will:
Be one of the first to program in the brand-new C++20 standard
Discover the SDL graphics and gaming library, and SSDL, the "Simple SDL" wrapper library
Get detailed help using the most common C++ compilers -- Visual Studio for Windows, and g++ (with Unix or MinGW) -- and their associated debuggers
Practice “anti-bugging” for easy fixes to common problems
Learn new concepts and skills from a variety of examples
Develop sound practices for becoming a productive programmer
Build a C++-based arcade game
Apply built-in Standard Template Library (STL) functions and classes for easy and efficient programming
Learn powerful data types including strings, stacks, vectors, and linked lists -- not by reading about them but by building them -- preparing you further for a career in programming