Beginning Modern C++ is based on and supersedes Ivor Horton s previous book, Beginning ANSI C++. This book is a tutorial for beginners in C++ and discussesa subset of C++ that is suitable for beginners. The language syntax will correspond to the proposed C++14 standard. The book will be environment neutraland doesnot presume any specific operating system or program development system. Some elements of the C++ standard library will be introduced. These will be the features that provide essential support for the language syntax that is discussed. While the Standard Template Library (STL) will not be discussed to a significant extent, a few elements from the STL that are important to the notion of modern C++ will be introduced. All language concepts that are explained in the book will be illustrated with working program examples. The book also includes a more substantial example that is developed over several chapters. Most chapters include exercises for the reader to test their knowledge. Code downloads are provided for examples from the text and solutions to the exercises. What you'll learn How to work with data types and do calculations in C++ 14 How to code with loops, arrays, strings, pointers, choices, decisions and more How to program with functions and deal with program files and pre-processing directives How to deal with data types and define your own data types, using classes and class operations How to handle operator overloading, inheritance, virtual functions, polymorphisms, and errors/exception handling How to use class templates and do input and output with C++ How to use the Standard Template Library How to integrate these into a contemporary example project Who this book is for This book is for industry practitioners and students wanting to learn C++ and use this as a reference guide for their applications. " Contents at a Glance......Page 3 Contents......Page 603 About the Author......Page 619 About the Technical Reviewer......Page 620 Introduction......Page 5 Modern C++......Page 7 Comments and Whitespace......Page 8 Functions......Page 9 Statements......Page 10 Namespaces......Page 11 Names and Keywords......Page 12 Code Presentation Style......Page 13 Creating an Executable......Page 14 Binary Numbers......Page 15 Hexadecimal Numbers......Page 17 Negative Binary Numbers......Page 18 Big-Endian and Little-Endian Systems......Page 20 Floating-Point Numbers......Page 21 ASCII Codes......Page 22 C++ Source Characters......Page 23 Escape Sequences......Page 24 Procedural and Object-Oriented Programming......Page 26 Summary......Page 27 Variables, Data, and Data Types......Page 29 Defining Integer Variables......Page 30 Decimal Integer Literals......Page 32 Octal Literals......Page 33 Calculations with Integers......Page 34 More on Assignment Operations......Page 36 The op= Assignment Operators......Page 38 The sizeof Operator......Page 40 Postfix Increment and Decrement Operations......Page 41 Defining Floating-Point Variables......Page 42 Floating-Point Literals......Page 43 Floating-Point Calculations......Page 44 Mathematical Functions......Page 46 Formatting Stream Output......Page 49 Mixed Expressions and Type Conversion......Page 51 Explicit Type Conversion......Page 53 Finding the Limits......Page 55 Working with Character Variables......Page 56 Working with Unicode Characters......Page 57 Lvalues and Rvalues......Page 58 Summary......Page 59 Operator Precedence and Associativity......Page 61 Bitwise Operators......Page 63 The Bitwise Shift Operators......Page 64 Logical Operations on Bit Patterns......Page 66 Using the Bitwise AND......Page 67 Using the Bitwise OR......Page 68 Using the Bitwise Exclusive OR......Page 69 Enumerated Data Types......Page 73 Synonyms for Data Types......Page 76 Global Variables......Page 77 External Variables......Page 81 Summary......Page 82 Comparing Data Values......Page 84 Applying the Comparison Operators......Page 85 The if Statement......Page 87 Nested if Statements......Page 90 Code-Neutral Character Handling......Page 91 The if-else Statement......Page 93 Nested if-else Statements......Page 94 Understanding Nested ifs......Page 95 Logical AND......Page 97 Logical Negation......Page 98 The Conditional Operator......Page 100 The switch Statement......Page 102 Unconditional Branching......Page 105 Statement Blocks and Variable Scope......Page 106 Summary......Page 107 Arrays......Page 109 Using an Array......Page 110 Understanding Loops......Page 111 The for Loop......Page 112 Avoiding Magic Numbers......Page 114 Determining the Size of an Array......Page 115 Controlling a for Loop with Floating-Point Values......Page 117 More Complex for Loop Control Expressions......Page 118 The Ranged-based for Loop......Page 120 The while Loop......Page 121 Allocating an Array at Runtime......Page 123 The do-while Loop......Page 125 Nested Loops......Page 127 Skipping Loop Iterations......Page 129 Indefinite Loops......Page 131 Arrays of Characters......Page 135 Multidimensional Arrays......Page 138 Initializing Multidimensional Arrays......Page 140 Setting Dimensions by Default......Page 141 Multidimensional Character Arrays......Page 142 Using array Containers......Page 144 Using std::vector Containers......Page 148 The Capacity and Size of a Vector......Page 149 Deleting Elements from a Vector container......Page 151 Summary......Page 152 What Is a Pointer ?......Page 154 The Address-Of Operator......Page 156 The Indirection Operator......Page 157 Pointers to Type char......Page 159 Arrays of Pointers......Page 161 Constant Pointers and Pointers to Constants......Page 163 Pointer Arithmetic......Page 165 Using Pointer Notation with an Array Name......Page 167 The Stack and the Heap......Page 170 Using the new and delete Operators......Page 171 Dynamic Allocation of Arrays......Page 172 Hazards of Dynamic Memory Allocation......Page 174 Fragmentation of the Free Store......Page 175 Raw Pointers and Smart Pointers......Page 176 Using unique_ptr Pointers......Page 177 Using shared_ptr Pointers......Page 178 Comparing shared_ptr Objects......Page 181 weak_ptr Pointers......Page 182 Understanding References......Page 183 Using a Reference Variable in a Range-Based for Loop......Page 184 Defining rvalue References......Page 185 Summary......Page 186 A Better Class of String......Page 188 Defining string Objects......Page 189 Concatenating Strings......Page 191 Accessing Characters in a String......Page 193 Accessing Substrings......Page 195 Comparing Strings......Page 196 The compare( ) Function......Page 198 Comparisons Using substr( )......Page 200 Searching Strings......Page 201 Searching for any of a Set of Characters......Page 203 Searching a String Backwards......Page 206 Inserting a String......Page 207 Replacing a Substring......Page 208 Removing Characters from a String......Page 210 Strings of wchar_t Characters......Page 211 Raw String Literals......Page 212 Summary......Page 213 Segmenting Your Programs......Page 215 Defining Functions......Page 216 The Function Body......Page 218 Function Declarations......Page 219 Function Prototypes......Page 220 Pass-by-Value......Page 221 Passing a Pointer to a Function......Page 223 Passing an Array to a Function......Page 224 const Pointer Parameters......Page 225 Passing a Multidimensional Array to a Function......Page 226 Pass-by-Reference......Page 227 References Can Be Risky......Page 228 Improving the Program......Page 230 References versus Pointers......Page 231 Arguments to main()......Page 232 Multiple Default Parameter Values......Page 233 Returning a Pointer......Page 235 Returning a Reference......Page 240 Static Variables......Page 241 Function Overloading......Page 243 Overloading and Reference Parameters......Page 245 Overloading with const Pointer Parameters......Page 247 Overloading and Default Argument Values......Page 248 A Sausage Machine for Functions......Page 249 Creating Instances of a Function Template......Page 250 Explicit Template Argument......Page 251 Function Template Specialization......Page 252 Function Templates and Overloading......Page 253 Function Templates with Multiple Parameters......Page 254 Non-Type Template Parameters......Page 255 Trailing Return Types......Page 256 Pointers to Functions......Page 257 Defining Pointers to Functions......Page 258 Recursion......Page 260 The Quicksort Algorithm......Page 263 The main() Function......Page 264 The extract_words() Function......Page 265 The sort() function......Page 266 The max_word_length() Function......Page 267 The show_words() Function......Page 268 Summary......Page 269 Introducing Lambda Expressions......Page 273 Naming a Lambda Expression......Page 274 Function Templates that Accept Lambda Expression Arguments......Page 276 A Function Parameter Type for Lambda Arguments......Page 277 Using the std::function Template Type......Page 278 The Capture Clause......Page 281 Capturing Specific Variables......Page 282 Using Lambda Expressions in a Template......Page 283 Recursion in Lambda Expressions......Page 285 Summary......Page 286 Understanding Translation Units......Page 288 Determining Linkage for a Name......Page 289 Preprocessing Your Source Code......Page 290 Defining Preprocessing Identifiers......Page 292 Including Header Files......Page 293 Preventing Duplication of Header File Contents......Page 294 Namespaces......Page 295 Defining a Namespace......Page 296 Functions and Namespaces......Page 299 Namespace Aliases......Page 302 Nested Namespaces......Page 303 Testing for Specific Identifier Values......Page 304 Multiple Choice Code Selection......Page 305 Standard Preprocessing Macros......Page 306 Integrated Debuggers......Page 307 Preprocessing Directives in Debugging......Page 308 Switching Off assert() Macros......Page 312 Static Assertions......Page 313 Summary......Page 314 Classes and Object-Oriented Programming......Page 316 Encapsulation......Page 317 Inheritance......Page 318 Polymorphism......Page 319 Terminology......Page 320 Defining a Class......Page 321 Constructors......Page 323 Defining Constructors Outside the Class......Page 325 Using a Constructor Initialization List......Page 327 Use of the explicit Keyword......Page 328 Delegating Constructors......Page 330 The Copy Constructor......Page 331 Accessing Private Class Members......Page 332 The Friend Functions of a Class......Page 334 The this Pointer......Page 337 Returning this from a Function......Page 338 const Objects and const Member Functions......Page 339 Casting Away const......Page 340 Arrays of Class Objects......Page 341 The Size of a Class Object......Page 342 Static Data Members......Page 343 Accessing Static Data Members......Page 346 Static Function Members......Page 347 Destructors......Page 348 Using Pointers As Class Members......Page 351 Defining the Package Class......Page 354 Defining the Truckload Class......Page 355 Implementing the Truckload Class......Page 356 Nested Classes......Page 360 Summary......Page 363 Implementing Operators for a Class......Page 366 Operators That Can Be Overloaded......Page 367 Implementing an Overloaded Operator......Page 368 Global Operator Functions......Page 370 Implementing Full Support for an Operator......Page 371 Implementing All Comparison Operators in a Class......Page 372 Operator Function Idioms......Page 374 Default Class Members......Page 375 Defining the Destructor......Page 376 Implementing the Assignment Operator......Page 378 Implementing Move Operations......Page 380 Overloading the Arithmetic Operators......Page 381 Improving Output Operations......Page 385 Implementing One Operator in Terms of Another......Page 387 Overloading the Subscript Operator......Page 388 Lvalues and the Overloaded Subscript Operator......Page 393 Overloading the Increment and Decrement Operators......Page 396 Overloading Type Conversions......Page 395 Function Objects......Page 397 Summary......Page 398 Classes and Object-Oriented Programming......Page 400 Hierarchies......Page 401 Inheritance vs. Aggregation......Page 402 Deriving Classes......Page 403 The Access Level of Inherited Class Members......Page 406 Choosing Access Specifiers in Class Hierarchies......Page 408 Changing the Access Specification of Inherited Members......Page 409 Constructor Operation in a Derived Class......Page 410 The Copy Constructor in a Derived Class......Page 413 The Default Constructor in a Derived Class......Page 415 Inheriting Constructors......Page 416 Destructors Under Inheritance......Page 417 The Order in Which Destructors Are Called......Page 418 Duplicate Data Member Names......Page 419 Multiple Inheritance......Page 420 Multiple Base Classes......Page 421 Inherited Member Ambiguity......Page 422 Repeated Inheritance......Page 425 Virtual Base Classes......Page 426 Summary......Page 427 Using a Base Class Pointer......Page 429 Calling Inherited Functions......Page 431 Virtual Functions......Page 434 Virtual Functions and Class Hierarchies......Page 438 Using final......Page 440 Access Specifiers and Virtual Functions......Page 441 Default Argument Values in Virtual Functions......Page 442 Using References to Call Virtual Functions......Page 444 Calling the Base Class Version of a Virtual Function......Page 445 Converting Between Pointers to Class Objects......Page 446 Casting Pointers Dynamically......Page 448 Determining the Polymorphic Type......Page 450 The Cost of Polymorphism......Page 451 Pure Virtual Functions......Page 452 Abstract Classes......Page 453 Abstract Classes As Interfaces......Page 455 Indirect Abstract Base Classes......Page 456 Destroying Objects Through a Pointer......Page 458 Summary......Page 460 Handling Errors......Page 462 Understanding Exceptions......Page 463 Throwing an Exception......Page 464 The Exception Handling Process......Page 466 Unhandled Exceptions......Page 467 Code That Causes an Exception to Be Thrown......Page 468 Nested try Blocks......Page 470 How It Works......Page 472 Class Objects as Exceptions......Page 473 Matching a Catch Handler to an Exception......Page 474 How It Works......Page 476 Catching Derived Class Exceptions with a Base Class Handler......Page 477 Rethrowing Exceptions......Page 479 Catching All Exceptions......Page 482 Function try Blocks......Page 484 Constructor try Blocks......Page 485 Standard Library Exceptions......Page 486 The Exception Class Definitions......Page 488 Deriving your own Exception Classes......Page 489 Summary......Page 492 Understanding Class Templates......Page 494 Defining Class Templates......Page 495 Template Parameters......Page 496 A Simple Class Template......Page 497 Constructor Templates......Page 499 The Destructor Template......Page 500 The Assignment Operator Template......Page 501 Instantiating a Class Template......Page 502 Static Members of a Class Template......Page 507 Non-Type Class Template Parameters......Page 508 Templates for Function Members with Non-Type Parameters......Page 511 Pointers and Arrays as Non-Type Parameters......Page 515 Default Values for Template Parameters......Page 516 Special Cases......Page 517 Using static_assert( ) in a Class Template......Page 518 Defining a Class Template Specialization......Page 519 Choosing between Multiple Partial Specializations......Page 520 Friends of Class Templates......Page 521 Class Templates with Nested Classes......Page 523 Function Templates for Stack Members......Page 525 Summary......Page 529 Input and Output in C++......Page 531 Binary Mode Operations......Page 532 Advantages of Using Streams......Page 533 Stream Classes......Page 534 Stream Insertion and Extraction Operations......Page 535 Stream Insertion Operations......Page 536 Stream Manipulators......Page 537 Manipulators with Arguments......Page 539 File Streams......Page 540 Writing a File in Text Mode......Page 541 Checking the State of a File Stream......Page 543 Reading the File......Page 544 Setting the Stream Open Mode......Page 546 Managing the Current Stream Position......Page 551 Unformatted Stream Operations......Page 553 Unformatted Stream Input......Page 554 Errors in Stream Input/Output......Page 556 Input/Output Errors and Exceptions......Page 558 Stream Operations in Binary Mode......Page 559 Writing Numeric Data in Binary......Page 561 File Read/Write Operations......Page 569 Random File Operations in Practice......Page 570 Implementing the Constructor......Page 571 Checking for the Existence of a File......Page 572 Finding a Prime that follows a Prime......Page 573 Implementing the Subscript Operator......Page 574 Using the Primes Class......Page 575 String Streams......Page 576 Using the Insertion Operator with Objects......Page 577 Using the Extraction Operator with Objects......Page 578 Object I/O in Binary Mode......Page 580 More Complex Objects in Streams......Page 583 Summary......Page 588 Index......Page 590 Beginning C is a tutorial for beginners in C and discusses a subset of C that is suitable for beginners. The language syntax corresponds to the C 14 standard. This book is environment neutral and does not presume any specific operating system or program development system. There is no assumption of prior programming knowledge. All language concepts that are explained in the book are illustrated with working program examples. Most chapters include exercises for you to test your knowledge. Code downloads are provided for examples from the text and solutions to the exercises and there is an additional download for a more substantial project for you to try when you have finished the book. This book introduces the elements of the C standard library that provide essential support for the language syntax that is discussed. While the Standard Template Library (STL) is not discussed to a significant extent, a few elements from the STL that are important to the notion of modern C are introduced and applied. Beginning C is based on and supersedes Ivor Horton’s previous book, Beginning ANSI C . Beginning C++ is a tutorial for beginners in C++ and discusses a subset of C++ that is suitable for beginners. The language syntax corresponds to the C++14 standard. This book is enviornment neutral and does not presume any specific operating system or program development system. There is no assumption of prior programming knowledge. All language concepts that are explained in the book are illustrated with working program examples. Most chaptersinclude exercises for you to test your knowledge. Code downloads are provided for examples from the text and solutions to the exercises and there is an additional download for a more substantial project for you to try when you have finished the book. This book introduces the elements of the C++ standard library that provide essential support for the language syntax that is discussed. While the Standard Template Library (STL) is not discussed to a significant extent, a few elements from the STL that are important tot he notion of modern C++ are introduced and applied. --Back cover.