User Manual (978-0-470-31726-6)Table of ContentsIntroduction1Introduction1What’s in This Book1What’s on the CD2What Is C++?2Conventions Used in This Book3How This Book Is Organized3And There’s More4Part I: Introduction to C++ Programming4Part II: Becoming a Functional C++ Programmer4Part III: Introduction to Classes5Part IV: Inheritance5Part V: Optional Features5Part VI: The Part of Tens5Icons Used in This Book6Where to Go from Here6Part I: Introduction to C++ Programming7Part I: Introduction to C++ Programming7Chapter 1: Writing Your First C++ Program9Grasping C++ Concepts9Installing Code::Blocks11Creating Your First C++ Program13Creating a project14Entering the C++ code15Cheating16Building your program17Executing Your Program18Reviewing the Annotated Program19Examining the framework for all C++ programs19Clarifying source code with comments20Basing programs on C++ statements21Writing declarations22Generating output22Calculating Expressions23Storing the results of an expression23Examining the remainder of Conversion24Chapter 2: Declaring Variables Constantly25Declaring Variables25Declaring Different Types of Variables26Reviewing the limitations of integers in C++27Solving the truncation problem28Looking at the limits of floating-point numbers29Declaring Variable Types31Types of constants32Range of Numeric Types33Special characters35Wide Loads on Char Highway36Are These Calculations Really Logical?37Mixed Mode Expressions37Automatic Declarations38Chapter 3: Performing Mathematical Operations41Performing Simple Binary Arithmetic41Decomposing Expressions43Determining the Order of Operations43Performing Unary Operations44Using Assignment Operators46Chapter 4: Performing Logical Operations49Why Mess with Logical Operations?49Using the Simple Logical Operators50Storing logical values51Using logical int variables53on floating-point variables53Expressing Binary Numbers55The decimal number system55Other number systems56The binary number system56Performing Bitwise Logical Operations58The single-bit operators58Using the bitwise operators60A simple test60Do something logical with logical calculations62Chapter 5: Controlling Program Flow63Controlling Program Flow with the Branch Commands63Executing Loops in a Program65Looping while a condition is true66Using the autoincrement/autodecrement feature67Using the for loop69Avoiding the dreaded infinite loop72Applying special loop controls73Nesting Control Commands75Switching to a Different Subject?77Part II: Becoming a Functional C++ Programmer79Part II: Becoming a Functional C++ Programmer79Chapter 6: Creating Functions81Writing and Using a Function81Defining our first function84Defining the sumSequence() function84Calling the function sumSequence()85Divide and conquer85Understanding the Details of Functions85Understanding simple functions86Understanding functions with arguments87Overloading Function Names90Defining Function Prototypes91Variable Storage Types93Chapter 7: Storing Sequences in Arrays95Arraying the Arguments for Arrays95Using an array97Initializing an array100Accessing too far into an array101Using arrays101Defining and using arrays of arrays101Using Arrays of Characters102Creating an array of characters102Creating a string of characters103Manipulating Strings with Character105Adding Some Library Functions107Making Room for Wide Strings109Chapter 8: Taking a First Look at C++ Pointers111Variable Size111What’s in an Address?113Address Operators113Using Pointer Variables115Using different types of pointers116Passing Pointers to Functions117Passing by value118Passing pointer values118Passing by reference119Constant const Irritation120Making Use of a Block of Memory Called the Heap122Limited scope122Examining the scope problem123Providing a solution using the heap124Chapter 9: Taking a Second Look at C++ Pointers127Defining Operations on Pointer Variables127Reexamining arrays in light of pointer variables128Applying operators to the address of an array130Expanding pointer operations to a string131Justifying pointer-based string manipulation133Applying operators to pointer types other than char134Contrasting a pointer with an array134When Is a Pointer Not?136Declaring and Using Arrays of Pointers137Utilizing arrays of character strings138Accessing the arguments to main()140Chapter 10: The C++ Preprocessor145What Is a Preprocessor?145Including Files146#Defining Things149Okay, how about not #defining things?152Enumerating other options153Including Things #if I Say So154Intrinsically Defined Objects156Typedef158Part III: Introduction to Classes159Part III: Introduction to Classes159Chapter 11: Examining Object-Oriented Programming161Abstracting Microwave Ovens161Preparing functional nachos162Preparing object-oriented nachos163Classifying Microwave Ovens163Why Classify?164Chapter 12: Adding Class to C++165Introducing the Class165The Format of a Class166Accessing the Members of a Class167Activating Our Objects167Simulating real-world objects168Why bother with member functions?168Adding a Member Function169Calling a Member Function170Accessing other members from a member function172Well Your Microscope Works)173Defining a Member Function in the Class175Keeping a Member Function After Class176Overloading Member Functions178Chapter 13: Point and Stare at Objects181Declaring Arrays of Objects181Declaring Pointers to Objects182Dereferencing an object pointer183Pointing toward arrow pointers184Passing Objects to Functions184Calling a function with an object value185Calling a function with an object pointer186Calling a function by using the reference operator188Why Bother with Pointers or References?189Returning to the Heap189Allocating heaps of objects190Comparing Pointers to References191Linking Up with Linked Lists191Performing other operations on a linked list192Hooking up with a LinkedListData program193A Ray of Hope: A List of Containers Linked to the C++ Library196Chapter 14: Protecting Members: Do Not Disturb197Protecting Members197Why you need protected members197Discovering how protected members work198Making an Argument for Using Protected Members200Protecting the internal state of the class200Using a class with a limited interface201Giving Nonmember Functions Access to Protected Members201Chapter 15: Why Do You Build Me Up, Just to Tear Me Down Baby?205Creating Objects205Using Constructors206Constructing a single object207Constructing multiple objects208Constructing a duplex209Dissecting a Destructor211Why you need the destructor211Working with destructors212Chapter 16: Making Constructive Arguments217Outfitting Constructors with Arguments217Using a constructor218Overloading the Constructor220Defaulting Default Constructors222Constructing Class Members224Constructing a complex data member224Constructing a constant data member228Reconstructing the Order of Construction229Local objects construct in order229Static objects construct only once230All global objects construct before main()231Global objects construct in no particular order231Members construct in the order in which they are declared233Constructors as a Form of Conversion233Chapter 17: Copying the Copy Copy Copy Constructor235Copying an Object235Why you need the copy constructor236Using the copy constructor236The Automatic Copy Constructor238Creating Shallow Copies versus Deep Copies240It’s a Long Way to Temporaries244Avoiding temporaries, permanently246Chapter 18: Static Members: Can Fabric Softener Help?247Defining a Static Member247Why you need static members247Using static members248Referencing static data members249Uses for static data members250Declaring Static Member Functions251What Is This About Anyway?253Part IV: Inheritance255Part IV: Inheritance255Chapter 19: Inheriting a Class257Do I Need My Inheritance?258How Does a Class Inherit?259Using a subclass261Constructing a subclass262Destructing a subclass263Having a HAS_A Relationship263Chapter 20: Examining Virtual Member Functions: Are They for Real?265Why You Need Polymorphism268How Polymorphism Works269When Is a Virtual Function Not?270Considering Virtual Considerations271Chapter 21: Factoring Classes273Factoring273Implementing Abstract Classes277Describing the abstract class concept278Making an honest class out of an abstract class279Passing abstract classes280Part V: Optional Features281Chapter 22: A New Assignment Operator, Should You Decide to Accept It283Comparing Operators with Functions283Inserting a New Operator284Creating Shallow Copies Is a Deep Problem285Overloading the Assignment Operator286Overloading the Subscript Operator291Chapter 23: Using Stream I/O293How Stream I/O Works293Default stream objects294Stream Input/Output295Open modes297Hey, file, what state are you in?298Can you show me an example?298Other Methods of the Stream Classes301Reading and writing streams directly303Controlling format305What’s up with endl?307Positioning the pointer within a file307Using the stringstream Subclasses308Manipulating Manipulators311Chapter 24: Handling Errors — Exceptions315Justifying a New Error Mechanism?317Examining the Exception Mechanism318What Kinds of Things Can I Throw?321Just Passing Through324Chapter 25: Inheriting Multiple Inheritance325Describing the Multiple Inheritance Mechanism325Straightening Out Inheritance Ambiguities327Adding Virtual Inheritance328Constructing the Objects of Multiple Inheritance335Voicing a Contrary Opinion335Chapter 26: Tempting C++ Templates337Generalizing a Function into a Template338Template Classes340Tips for Using Templates343Chapter 27: Standardizing on the Standard Template Library345The string Container346Iterating through Lists351Making your way through a list353Operations on an entire list354Can you show me an example?355Part VI: The Part of Tens357Part VI: The Part of Tens357Chapter 28: Ten Ways to Avoid Adding Bugs to Your Program359Enable All Warnings and Error Messages359Adopt a Clear and Consistent Coding Style360Limit the Visibility360Comment Your Code While You Write It362Single-Step Every Path at Least Once362Avoid Overloading Operators363Manage the Heap Systematically363Use Exceptions to Handle Errors363Declare Destructors Virtual364Avoid Multiple Inheritance365Chapter 29: Ten Major Recent Additions to C++367Use Smart Pointers367Initialize Variables with a Variable-Length List368Initialize Data Members Inline369Instantiate an Extern Template370Implement Thread Local Storage371Use Rvalue References371Implement Concepts372Define Lamda Expressions373Define Variadic Templates374Use typeid()374Appendix: About the CD377Appendix: About the CD377System Requirements377Using the CD378What You’ll Find on the CD378CPP programs379Code::Blocks development environment379Troubleshooting380Customer Care381Index383Index383Size: 80.5 KBPages: 12Language: EnglishOpen manual