Introduction 1 About This Book 1 Foolish Assumptions 4 Icons Used in This Book 4 Beyond the Book 5 Where to Go from Here 6 Book 1: Getting Started with C++ 7 Chapter 1: Configuring Your Desktop System 9 Obtaining a Copy of C++ 20 10 Obtaining Code::Blocks 11 Installing Code::Blocks 12 Working with Windows 12 Working with Mac OS X 13 Using the standard Linux installation 14 Using the graphical Linux installation 15 Touring the Essential Code::Blocks Features 17 Starting Code::Blocks for the first time 18 Opening the sample projects 19 Viewing the essential windows 20 Using Other IDEs 25 Chapter 2: Configuring Your Mobile System 27 Obtaining CppDroid 28 Understanding why CppDroid is such a great choice 29 Getting your copy of CppDroid 31 Ensuring you get a good install 32 Considering Other Alternatives 32 Working with C4Droid 33 Getting multiple language support with AIDE 33 Using web-based IDEs 34 Touring the Essential CppDroid Features 35 Getting started with CppDroid 35 Accessing an example 37 Working with a simple online project 37 Accessing your source code 38 Considering differences with the desktop environment 39 Obtaining CppDroid Help 40 Working with the Help documentation 40 Getting community support 41 Using the free examples 42 Accessing the tutorials 43 Chapter 3: Creating Your First C++ Application 45 Code::Blocks Creating a Project 46 Understanding projects 46 Defining your first project 47 Building and executing your first application 52 Typing the Code 53 Starting with Main 55 Showing Information 55 Doing some math 60 Tabbing your output 66 Let Your Application Run Away 67 Chapter 4: Storing Data in C++ 69 Putting Your Data Places: Variables 70 Creating an integer variable 70 Declaring multiple variables 73 Changing values 74 Setting one variable equal to another 74 Initializing a variable 75 Creating a great name for yourself 76 Manipulating Integer Variables 78 Adding integer variables 78 Subtracting integer variables 82 Multiplying integer variables 84 Dividing integer variables 86 Characters 88 Null character 89 Nonprintable and other cool characters 89 Strings 93 Getting a part of a string 94 Changing part of a string 95 Adding onto a string 96 Adding two strings 97 Making Decisions Using Conditional Operators 98 Telling the Truth with Boolean Variables 100 Reading from the Console 102 Chapter 5: Directing the Application Flow 105 Doing This or Doing That 106 Evaluating Conditions in C++ 107 Finding the right C++ operators 108 Combining multiple evaluations 110 Including Evaluations in C++ Conditional Statements 111 Deciding what if and also what else 112 Going further with the else and if 113 Repeating Actions with Statements That Loop 115 Understanding how computers use loops 116 Looping situations 116 Looping for 117 Performing a simple for loop 118 Using multiple initialization variables 123 Working with ranges 126 Placing a condition within the declaration 128 Letting C++ determine the type 129 Looping while 130 Doing while 132 Breaking and continuing 133 Breaking 134 Continuing 135 Nesting loops 136 Chapter 6: Dividing Your Work with Functions 139 Dividing Your Work 139 Calling a Function 144 Passing a variable 146 Passing multiple variables 147 Writing Your Own Functions 148 Defining the AddOne() function 149 Seeing how AddOne() is called 150 Taking the AddOne() Function apart 150 Considering the AddOne() parameter 151 Understanding the AddOne() name and type 152 Improving On the Basic Function 153 Using multiple parameters or no parameters 153 Returning nothing 156 Keeping your variables local 157 Forward references and function prototypes 159 Writing two versions of the same function 161 Calling All String Functions 163 Inserting a string into a string 163 Removing parts of a string 164 Replacing parts of a string 164 Using the string functions together 164 Understanding main() 165 Chapter 7: Splitting Up Source Code Files 169 Creating Multiple Source Files 170 Adding a new source code file 170 Removing an existing source code file 173 Creating a project with multiple existing files 173 Getting multiple files to interact 177 Sharing with Header Files 179 Adding the header only once 182 Using angle brackets or quotes 182 Sharing Variables among Source Files 183 Using the Mysterious Header Wrappers 185 Chapter 8: Referring to Your Data Through Pointers 187 Understanding the Changes in Pointers for C++ 20 188 Avoiding broken code 188 Considering the issues 189 Writing cleaner and less bug-prone code 191 Heaping and Stacking the Variables 192 Getting a variable''s address 196 Changing a variable by using a pointer 198 Pointing at a string 200 Pointing to something else 203 Tips on pointer variables 204 Creating New Raw Pointers 205 Using new 206 Using an initializer 208 Freeing Raw Pointers 209 Working with Smart Pointers 211 Creating smart pointers using std::unique_ptr and std::shared_ptr 212 Defining nullable values using std::optional and std::nullopt 216 Passing Pointer Variables to Functions 218 Returning Pointer Variables from Functions 221 Part 2: Understanding Objects and Classes 225 Chapter 1: Working with Classes 227 Understanding Objects and Classes 227 Classifying classes and objects 230 Describing methods and data 231 Implementing a class 232 Separating method code 237 The parts of a class 240 Working with a Class 241 Accessing members 241 Using classes and raw pointers 244 Using classes and smart pointers 248 Passing objects to functions 249 Using const parameters in functions 251 Using the this pointer 252 Overloading methods 256 Starting and Ending with Constructors and Destructors 259 Starting with constructors 259 Ending with destructors 260 Sampling constructors and destructors 260 Adding parameters to constructors 263 Building Hierarchies of Classes 264 Creating a hierarchy in C++ 265 Understanding types of inheritance 266 Creating and Using Object Aliases 267 Chapter 2: Using Advanced C++ Features 269 Filling Your Code with Comments 270 Converting Types 272 Understanding how int and string conversions work 272 Seeing int and string conversions in action 273 Considering other conversion issues 276 Reading from the Console 277 Understanding Preprocessor Directives 282 Understanding the basics of preprocessing 282 Creating constants and macros with #define 283 Performing conditional compilation 286 Exercising the basic preprocessor directives 288 Using Constants 292 Using Switch Statements 295 Supercharging enums with Classes 298 Working with Random Numbers 300 Storing Data in Arrays 302 Declaring and accessing an array 303 Arrays of pointers 304 Passing arrays to functions 306 Adding and subtracting pointers 307 Chapter 3: Planning and Building Objects 309 Recognizing Objects 310 Observing the Mailboxes class 312 Observing the Mailbox class 314 Finding other objects 315 Encapsulating Objects 316 Considering the Application Programming Interface 316 Understanding properties 316 Choosing between private and protected 318 Defining a process 318 Implementing properties 319 Building Hierarchies 322 Establishing a hierarchy 322 Protecting members when inheriting 324 Overriding methods 330 Specializing with polymorphism 332 Getting abstract about things 333 Chapter 4: Building with Design Patterns 335 Delving Into Pattern History 336 Introducing a Simple Pattern: the Singleton 337 Using an existing pattern 337 Creating a singleton pattern class 338 Watching an Instance with an Observer 341 Understanding the observer pattern 341 Defining an observer pattern class 343 Observers and the Standard C++ Library 346 Automatically adding an observer 347 Mediating with a Pattern 349 Defining the mediator pattern scenario 350 Outlining the car example 351 Creating the car example 354 Book 3: Understanding Functional Programming 367 Chapter 1: Considering Functional Programming 369 Understanding How Functional Programming Differs 370 Defining an Impure Language 373 Considering the requirements 373 Understanding the C++ functional limitations 374 Seeing Data as Immutable 375 Working with immutable variables 376 Working with.
C++ All-In-One for Dummies