Зарегистрироваться
Восстановить пароль
FAQ по входу

Horton Ivor, Van Weert Peter. Beginning C++23 From Beginner to Pro

  • Файл формата zip
  • размером 8,47 МБ
  • содержит документ формата mobi
Horton Ivor, Van Weert Peter. Beginning C++23 From Beginner to Pro
7th Edition. — Apress Media LLC., 2023. — 1819 р. — ISBN-13: 978-1-4842-9343-0.
Begin your programming journey with C++ , starting with the basics and progressing through step-by-step examples that will help you become a proficient C++ programmer. This book includes new features from the C++23 standard. All you need are Beginning C++23 and any recent C++ compiler and you'll soon be writing real C++ programs.
There is no assumption of prior programming knowledge. All language concepts that are explained in the book are illustrated with working program examples, and all chapters include exercises for you to test and practice your knowledge. Free source code downloads are provided for all examples from the text and solutions to the exercises.
This latest edition has been fully updated to the latest version of the language, C++23, and to all conventions and best practices of modern C++. This book also introduces elements of the C++ Standard Library that provide essential support for C++23. After completing this book, you will have the knowledge and skills needed to build your first C++ applications.
What You Will Learn
Begin programming with the C++23 standard
Carry out modular programming in C++
Work with arrays and loops, pointers and references, strings, and more
Write your own functions, types, and operators
Discover the essentials of object-oriented programming
Use overloading, inheritance, virtual functions, and polymorphism
Write generic function and class templates, and make them safer using concepts
Learn the ins and outs of containers, algorithms, and ranges
Use auto type declarations, exceptions, move semantics, lambda expressions, and much more
Who This Book Is For
Programmers new to C++ and those who may be looking for a refresh primer on C++ in general.
About the Authors
About the Technical Reviewer
Introduction
Basic Ideas
Modern C
Standard Libraries
C++ Program Concepts
Source Files
Comments and Whitespace
The Standard Library and Modules
Functions
Statements
Text Output
return Statements
Namespaces
Identifiers and Keywords
Streams
Classes and Objects
Templates
Code Appearance and Programming Style
Creating an Executable
Procedural and Object-Oriented Programming
Representing Numbers
Binary Numbers
Hexadecimal Numbers
Negative Binary Numbers
Octal Values
Big-Endian and Little-Endian Systems
Floating-Point Numbers
Representing Characters
ASCII Codes
UCS and Unicode
Summary
Introducing Fundamental Types of Data
Variables, Data, and Data Types
Defining Integer Variables
Zero Initialization
Defining Variables with Fixed Values
Integer Literals
Decimal Integer Literals
Hexadecimal Literals
Octal Literals
Binary Literals
Calculations with Integers
Compound Arithmetic Expressions
Assignment Operations
The op= Assignment Operators
Incrementing and Decrementing Integers
Postfix Increment and Decrement Operations
Floating-Point Variables
Standard Floating-Point Data Types
Extended Floating-Point Data Types
Floating-Point Literals
Finding the Limits
Finding Other Properties of Fundamental Types
The sizeof Operator
Floating-Point Calculations
Mathematical Constants
Mathematical Functions
Invalid Floating-Point Results
Pitfalls
Mixed Expressions and Type Conversion
Explicit Type Conversion
Old-Style Casts
The auto Keyword
Working with Character Variables
Working with Unicode Characters
Unicode Literals and Source File Encodings
Escape Sequences
Escaping Unicode Characters
Formatting
Modern Formatting
Formatting Stream Output
Summary
Working with Fundamental Data Types
Operator Precedence and Associativity
Bitwise Operators
The Bitwise Shift Operators
Logical Operations on Bit Patterns
The Lifetime of a Variable
Global Variables
Enumerated Data Types
Aliases for Data Types
Summary
Making Decisions
Comparing Data Values
Applying the Comparison Operators
Comparing Floating-Point Values
The Spaceship Operator
The if Statement
Nested if Statements
Character Classification and Conversion
The if-else Statement
Nested if-else Statements
Understanding Nested ifs
Logical Operators
Logical AND
Logical OR
Logical Negation
Combining Logical Operators
Logical Operators on Integer Operands
Logical Operators vs. Bitwise Operators
The Conditional Operator
The switch Statement
Fallthrough
Switching on Enumeration Values
Statement Blocks and Variable Scope
Initialization Statements
Summary
Arrays and Loops
Arrays
Using an Array
Understanding Loops
The for Loop
Avoiding Magic Numbers
Defining the Array Size with the Braced Initializer
Determining the Size of an Array
Controlling a for Loop with Floating-Point Values
More Complex for Loop Control Expressions
The Comma Operator
The Range-Based for Loop
The while Loop
The do-while Loop
Nested Loops
Skipping Loop Iterations
Breaking Out of a Loop
Indefinite Loops
Controlling a for Loop with Unsigned Integers
Arrays of Characters
Multidimensional Arrays
Initializing Multidimensional Arrays
Multidimensional Character Arrays
Allocating an Array at Runtime
Alternatives to Using an Array
Using array T,N Containers
Using std::vector T Containers
Formatting Ranges
Summary
Pointers and References
What Is a Pointer
The Address-Of Operator
The Indirection Operator
Why Use Pointers
Pointers to Type char
Arrays of Pointers
Constant Pointers and Pointers to Constants
Pointers and Arrays
Pointer Arithmetic
Using Pointer Notation with an Array Name
Dynamic Memory Allocation
The Stack and the Free Store
Using the new and delete Operators
Dynamic Allocation of Arrays
Member Selection Through a Pointer
Hazards of Dynamic Memory Allocation
Dangling Pointers and Multiple Deallocations
Allocation/Deallocation Mismatch
Memory Leaks
Fragmentation of the Free Store
Golden Rule of Dynamic Memory Allocation
Raw Pointers and Smart Pointers
Using unique_ptr T Pointers
Using shared_ptr T Pointers
Understanding References
Defining References
Using a Reference Variable in a Range-Based for Loop
Summary
Working with Strings
A Better Class of String
Defining string Objects
Copying and Marking Substrings
Formatting and Reading String Objects
Operations with String Objects
Accessing Characters in a String
Accessing Substrings
Comparing Strings
Searching Strings
Modifying a String
std::string vs. std::vector char
Converting Strings into Numbers
Strings of International Characters
Strings of wchar_t Characters
Objects That Contain Unicode Strings
Raw String Literals
Summary
Defining Functions
Segmenting Your Programs
Functions in Classes
Characteristics of a Function
Defining Functions
The Function Body
Return Values
Function Declarations
Passing Arguments to a Function
Pass-by-Value
Pass-by-Reference
Default Argument Values
Multiple Default Argument Values
Arguments to main()
Returning Values from a Function
Returning a Pointer
Returning a Reference
Returning vs. Output Parameters
Return Type Deduction
Static Local Variables
Function Overloading
Overloading and Pointer Parameters
Overloading and Reference Parameters
Overloading and const Parameters
Overloading and Default Argument Values
Recursion
Basic Examples of Recursion
Recursive Algorithms
Constant Expressions
constexpr Variables
constexpr Functions
Limitations to Constant Expressions
Summary
Vocabulary Types
Working with Optional Values
std::optional
std::expected
String Views: The New Reference-to-const-string
Using String View Function Parameters
A Proper Motivation
Spans: The New Reference-to-vector or -array
Writing Through a Span
Spans of const Elements
Fixed-Size Spans
Summary
Function Templates
Function Templates
Creating Instances of a Function Template
Template Type Parameters
Explicit Template Arguments
Function Template Specialization
Function Templates and Overloading
Function Templates with Multiple Parameters
Return Type Deduction in Templates
decltype(auto)
constexpr If
Default Values for Template Parameters
Non-Type Template Parameters
Templates for Functions with Fixed-Size Array Arguments
Abbreviated Function Templates
Limitations to Abbreviated Function Templates
Summary
Modules and Namespaces
Modules
Your First Module
Export Blocks
Separating Interface from Implementation
Reachability vs. Visibility
Exporting Import Declarations
Managing Larger Modules
Namespaces
The Global Namespace
Defining a Namespace
Nested Namespaces
Namespaces and Modules
Functions and Namespaces
Using Directives and Declarations
Namespace Aliases
Summary
Defining Your Own Data Types
Classes and Object-Oriented Programming
Encapsulation
Inheritance
Polymorphism
Terminology
Defining a Class
Creating Objects of a Class
Constructors
Default Constructors
Defining a Class Constructor
Using the default Keyword
Defining Functions Outside the Class
Default Arguments for Constructor Parameters
Using a Member Initializer List
Using the explicit Keyword
Delegating Constructors
The Copy Constructor
Defining Classes in Modules
Accessing Private Class Members
The this Pointer
Returning this from a Function
const Objects and const Member Functions
const Member Functions
const Correctness
Overloading on const
Casting Away const
Using the mutable Keyword
Friends
The Friend Functions of a Class
Friend Classes
Arrays of Class Objects
The Size of a Class Object
Static Members of a Class
Static Member Variables
Accessing Static Member Variables
Static Constants
Static Member Variables of the Class Type Itself
Static Member Functions
Destructors
constexpr Member Functions
consteval Constructors
Using Pointers as Class Members
The Truckload Example
Nested Classes
Nested Classes with Public Access
A Better Mechanism for Traversing a Truckload: Iterators
Summary
Operator Overloading
Implementing Operators for a Class
Operator Overloading
Implementing an Overloaded Operator
Nonmember Operator Functions
Implementing Full Support for an Operator
Operators That Can Be Overloaded
Restrictions and Key Guideline
Operator Function Idioms
Supporting All Comparison Operators
Defaulting Comparison Operators
Overloading the Operator for Output Streams
Overloading the Arithmetic Operators
Implementing One Operator in Terms of Another
Member vs. Nonmember Functions
Operator Functions and Implicit Conversions
Overloading Unary Operators
Overloading the Increment and Decrement Operators
Overloading the Subscript Operator
Modifying the Result of an Overloaded Subscript Operator
Function Objects
Overloading Type Conversions
Potential Ambiguities with Conversions
Overloading the Assignment Operator
Implementing the Copy Assignment Operator
Copy Assignment vs. Copy Construction
Deleting the Copy Assignment Operator
Assigning Different Types
Summary
Inheritance
Classes and Object-Oriented Programming
Hierarchies
Inheritance in Classes
Inheritance vs. Aggregation and Composition
Deriving Classes
Protected Members of a Class
The Access Level of Inherited Class Members
Access Specifiers and Class Hierarchies
Choosing Access Specifiers in Class Hierarchies
Changing the Access Specification of Inherited Members
Constructors in a Derived Class
The Copy Constructor in a Derived Class
The Default Constructor in a Derived Class
Inheriting Constructors
Destructors Under Inheritance
Duplicate Member Variable Names
Duplicate Member Function Names
Multiple Inheritance
Multiple Base Classes
Inherited Member Ambiguity
Repeated Inheritance
Virtual Base Classes
Converting Between Related Class Types
Summary
Polymorphism
Understanding Polymorphism
Using a Base Class Pointer
Calling Inherited Functions
Virtual Functions
Requirements for Virtual Function Operation
Using the override Specifier
Using final
Virtual Functions and Class Hierarchies
Access Specifiers and Virtual Functions
Default Argument Values in Virtual Functions
Using References to Call Virtual Functions
Polymorphic Collections
Destroying Objects Through a Pointer
Virtual Destructors
Converting Between Pointers to Class Objects
Dynamic Casts
Casting Pointers Dynamically
Dynamic Casts and const
Converting References
Calling the Base Class Version of a Virtual Function
Calling Virtual Functions from Constructors or Destructors
How Polymorphic Function Calls Work
Determining the Dynamic Type
Pure Virtual Functions
Abstract Classes
An Abstract Box Class
Abstract Classes as Interfaces
Summary
Runtime Errors and Exceptions
Handling Errors
Understanding Exceptions
Throwing an Exception
The Exception-Handling Process
Code That Causes an Exception to Be Thrown
Nested try Blocks
Class Objects as Exceptions
Matching a Catch Handler to an Exception
Catching Derived Class Exceptions with a Base Class Handler
Rethrowing Exceptions
Unhandled Exceptions
Catching All Exceptions
Functions That Don’t Throw Exceptions
The noexcept Specifier
Exceptions and Destructors
Exceptions and Resource Leaks
Resource Acquisition Is Initialization
Standard RAII Classes for Dynamic Memory
Standard Library Exceptions
The Exception Class Definitions
Using Standard Exceptions
Stack Traces
Summary
Class Templates
Understanding Class Templates
Defining Class Templates
Template Type Parameters
A Simple Class Template
Defining Member Functions of a Class Template
Constructor Templates
The Destructor Template
Subscript Operator Templates
The Assignment Operator Template
Class Template Instantiation
Explicit Template Instantiation
Testing the Array Class Template
Non-Type Class Template Parameters
Templates for Member Functions with Non-Type Parameters
Arguments for Non-Type Parameters
Non-Type Template Arguments vs. Constructor Arguments
Default Values for Template Parameters
Class Template Argument Deduction
Class Template Specialization
Defining a Class Template Specialization
Partial Template Specialization
Class Templates with Nested Classes
Function Templates for Stack Members
Dependent Names Nuisances
Dependent Type Names
Dependent Base Classes
Summary
Move Semantics
Lvalues and Rvalues
Rvalue References
Moving Objects
Defining Move Members
Explicitly Moved Objects
Move-Only Types
Extended Use of Moved Objects
A Barrel of Contradictions
std::move() Does Not Move
An Rvalue Reference Is an Lvalue
Defining Functions Revisited
Pass-by-Rvalue-Reference
The Return of Pass-by-Value
Return-by-Value
Defining Move Members Revisited
Always Add noexcept
The “Move-and-Swap” Idiom
Special Member Functions
Default Move Members
The Rule of Five
The Rule of Zero
Summary
First-Class Functions
Pointers to Functions
Defining Pointers to Functions
Callback Functions for Higher-Order Functions
Type Aliases for Function Pointers
Function Objects
Basic Function Objects
Standard Function Objects
Parameterized Function Objects
Lambda Expressions
Defining a Lambda Expression
Naming a Lambda Closure
Passing a Lambda Expression to a Function Template
Generic Lambdas
The Capture Clause
The std::function Template
Summary
Containers and Algorithms
Containers
Sequence Containers
Stacks and Queues
Associative Containers
Iterators
The Iterator Design Pattern
Iterators for Standard Library Containers
Iterators for Arrays
Algorithms
A First Example
Finding Elements
Handling Multiple Output Values
The Remove-Erase Idiom
Sorting
Parallel Algorithms
Ranges and Views
Range-Based Algorithms
Views
Summary
Constrained Templates and Concepts
Unconstrained Templates
Constrained Templates
Concepts
Concept Definitions and Expressions
Requires Expressions
Asserting That a Type Models a Concept
Standard Concepts
Requires Clauses
Shorthand Notation
Constrained Function Templates
Constrained Class Templates
Constrained Class Members
Constraint-Based Overloading
Constraining Auto
Summary
Appendix: Preprocessing, ODR, Linkage, and Header Files
Index
  • Чтобы скачать этот файл зарегистрируйтесь и/или войдите на сайт используя форму сверху.
  • Регистрация