Author(s): Richard Grimes
Year: 2017
Cover
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Table of Contents
Preface
Chapter 1: Starting with C++
What will you find in this chapter?
What is C++?
Installing Visual C++
Setting up
Downloading the installation files
Installing Visual Studio
Registering with Microsoft
Examining C++ projects
Compilers
Linking the code
Source files
A simple example
Creating source files
Compiling the code
Passing parameters between the command-line and an executable
The preprocessor and symbols
Defining constants
Using macros
Using symbols
Using pragmas
Dependencies
Libraries
Pre-compiled headers
Project structure
Managing dependencies
Makefiles
Writing a simple project
The project structure
Creating the precompiled header
Creating the main file
Using input and output streams
Using time functions
Building the executable
Testing the code
Changing the project
Summary
Chapter 2: Understanding Language Features
Writing C++
Using white space
Formatting code
Writing statements
Working with expressions
Using the comma operator
Using types and variables
Using constants and literals
Defining constants
Using constant expressions
Using enumerations
Declaring pointers
Using namespaces
C++ scoping of variables
Using operators
Exploring the built-in operators
Arithmetic operators
Increment and decrement operators
Bitwise operators
Boolean operators
Bitwise shift operators
Assignment operators
Controlling execution flow
Using conditional statements
Selecting
Looping
Looping with iteration
Conditional loops
Jumping
Using C++ language features
Summary
Chapter 3: Exploring C++ Types
Exploring built-in types
Integers
Specifying integer literals
Using bitset to show bit patterns
Determining integer byte order
Floating point types
Specifying floating point literals
Characters and strings
Character types
Using character macros
Specifying character literals
Specifying string literals
Unicode literals
Raw strings
String byte order
Boolean
void
Initializers
Default values
Declarations without a type
Storage classes
Using type aliases
Aggregating data in record types
Structures
Initializing
Structure fields
Using structure names
Determining alignment
Storing data in the same memory with unions
Accessing runtime type information
Determining type limits
Converting between types
Type conversions
Promoting conversions
Narrowing conversions
Narrowing to bool
Converting signed types
Casting
Casting away const-ness
Casting without runtime checks
Casting pointers without runtime checks
Casting with runtime checks
Casting with list initializer
Using C casts
Using C++ types
Summary
Chapter 4: Working with Memory, Arrays, and Pointers
Using memory in C++
Using C++ pointer syntax
Using null pointers
Types of memory
Pointer arithmetic
Using arrays
Function parameters
Multidimensional arrays
Passing multidimensional arrays to functions
Using arrays of characters
Comparing strings
Preventing buffer overruns
Using pointers in C++
Accessing out of bounds
Pointers to deallocated memory
Converting pointers
Constant pointers
Changing the type pointed to
Allocating memory in code
Allocating individual objects
Allocating arrays of objects
Handling failed allocations
Using other versions of the new operator
Memory lifetime
The Windows SDK and pointers
Memory and the C++ Standard Library
Standard Library arrays
Using the stack-based array class
Using the dynamically allocated vector class
References
Constant references
Returning references
Temporaries and references
The rvalue references
Ranged for and references
Using pointers in practice
Creating the project
Adding a task object to the list
Deleting the task list
Iterating the task list
Inserting items
Summary
Chapter 5: Using Functions
Defining C++ functions
Declaring and defining functions
Specifying linkage
Inlining
Determining the return type
Naming the function
Function parameters
Specifying exceptions
Function body
Using function parameters
Passing Initializer lists
Using default parameters
Variable number of parameters
Initializer lists
Argument lists
Function features
Call stack
Specifying calling conventions
Using C linkage
Specifying how the stack Is maintained
Using recursion
Overloading functions
Functions and scope
Deleted functions
Passing by value and passing by reference
Designing functions
Pre- and post-conditions
Using invariants
Function pointers
Remember the parentheses!
Declaring function pointers
Using function pointers
Templated functions
Defining templates
Using template parameter values
Specialized templates
Variadic templates
Overloaded operators
Function objects
Introducing lambda expressions
Using functions in C++
Summary
Chapter 6: Classes
Writing classes
Reviewing structures
Defining classes
Defining class behavior
Using the this pointer
Using the scope resolution operator
Defining class state
Creating objects
Construction of objects
Defining constructors
Delegating constructors
Copy constructor
Converting between types
Making friends
Marking constructors as explicit
Destructing objects
Assigning objects
Move semantics
Declaring static members
Defining static members
Using static and global objects
Named constructors
Nested classes
Accessing const objects
Using objects with pointers
Getting pointers to object members
Operator overloading
Defining function classes
Defining conversion operators
Managing resources
Writing wrapper classes
Using smart pointers
Managing exclusive ownership
Sharing ownership
Handling dangling pointers
Templates
Using classes
Summary
Chapter 7: Introduction to Object-Orientated Programming
Inheritance and composition
Inheriting from a class
Overriding methods and hiding names
Using pointers and references
Access levels
Changing access level through inheritance
Inheritance access levels
Multiple inheritance
Object slicing
Introducing polymorphism
Virtual methods
Virtual method tables
Multiple inheritance and virtual method tables
Virtual methods, construction, and destruction
Containers and virtual methods
Friends and inheritance
Override and final
Virtual inheritance
Abstract classes
Obtaining type information
Smart pointers and virtual methods
Interfaces
Class relationships
Using mixin classes
Using polymorphism
Summary
Chapter 8: Using the Standard Library Containers
Working with pairs and tuples
Containers
Sequence containers
List
Forward list
Vector
Deque
Associative containers
Maps and multimaps
Sets and multisets
Unordered containers
Special purpose containers
Using iterators
Input and output iterators
Stream iterators
Using iterators with the C Standard Library
Algorithms
Iteration of items
Getting information
Comparing containers
Changing Items
Finding Items
Sorting items
Using the numeric libraries
Compile time arithmetic
Complex numbers
Using the Standard Library
Summary
Chapter 9: Using Strings
Using the string class as a container
Getting information about a string
Altering strings
Searching strings
Internationalization
Using facets
Strings and numbers
Converting strings to numbers
Converting numbers to strings
Using stream classes
Outputting floating point numbers
Outputting integers
Outputting time and money
Converting numbers to strings using streams
Reading numbers from strings using streams
Using regular expressions
Defining regular expressions
Standard Library classes
Matching expressions
Using iterators
Replacing strings
Using strings
Creating the project
Processing header subitems
Summary
Chapter 10: Diagnostics and Debugging
Preparing your code
Invariants and conditions
Conditional compilation
Using pragmas
Adding informational messages
Compiler switches for debugging
Pre-processor symbols
Producing diagnostic messages
Trace messages with the C runtime
Tracing messages with Windows
Using asserts
Application termination
Error values
Obtaining message descriptions
Using the Message Compiler
C++ exceptions
Exception specifications
C++ exception syntax
Standard exception classes
Catching exceptions by type
Function try blocks
System errors
Nested exceptions
Structured Exception Handling
Compiler exception switches
Mixing C++ and SEH exception handling
Writing exception-safe classes
Summary
Index