Preface to the Second Edition p. iii Preface to the First Edition p. vi Brief Contents p. ix Introduction to C++ p. 1 A Review of Structures p. 1 The Need for Structures p. 1 Creating a New Data Type Using Structures p. 4 Using Structures in Application Programs p. 5 Procedure-Oriented Programming Systems p. 5 Object-Oriented Programming Systems p. 7 Comparison of C++ with C p. 8 Console Input/Output in C++ p. 9 Console Output p. 9 Console Input p. 12 Variables in C++ p. 13 Reference Variables in C++ p. 14 Function Prototyping p. 19 Function Overloading p. 21 Default Values for Formal Arguments of Functions p. 23 Inline Functions p. 25 Classes and Objects p. 31 Introduction to Classes and Objects p. 31 Private and Public Members p. 33 Objects p. 36 Scope Resolution Operator p. 37 Creating Libraries Using the Scope Resolution Operator p. 38 Using Classes in Application Programs p. 39 this Pointer p. 40 Data Abstraction p. 45 Explicit Address Manipulation p. 47 Arrow Operator p. 47 Calling One Member Function from Another p. 48 Member Functions and Member Data p. 49 Overloaded Member Functions p. 49 Default Values for Formal Arguments of Member Functions p. 51 Inline Member Functions p. 52 Constant Member Functions p. 52 Mutable Data Members p. 54 Friends p. 54 Static Members p. 59 Objects and Functions p. 65
Objects and Arrays p. 66 Arrays of Objects p. 67 Arrays Inside Objects p. 67 Namespaces p. 68 Nested Inner Classes p. 71 Dynamic Memory Management p. 78 Introduction p. 78 Dynamic Memory Allocation p. 79 Dynamic Memory Deallocation p. 84 set_new_handler() function p. 88 Constructors and Destructors p. 92 Constructors p. 92 Zero-argument Constructor p. 94 Parameterized Constructors p. 97 Explicit Constructors p. 103 Copy Constructor p. 105 Destructors p. 109 Philosophy of OOPS p. 112 Inheritance p. 117 Introduction p. 117 Effects of Inheritance p. 118 Benefits of Inheritance p. 120 Inheritance in Actual Practice p. 120 Base Class and Derived Class Objects p. 121 Accessing Members of the Base Class in the Derived Class p. 121 Base Class and Derived Class Pointers p. 122 Function Overriding p. 127 Base Class Initialization p. 129 Protected Access Specifier p. 132 Deriving by Different Access Specifiers p. 133 Deriving by the Public Access Specifier p. 133 Deriving by the Protected Access Specifier p. 135 Deriving by the Private Access Specifier p. 136 Different Kinds of Inheritance p. 139 Multiple Inheritance p. 139 Ambiguities in Multiple Inheritance p. 141 Multi-level Inheritance p. 145 Hierarchical Inheritance p. 147 Hybrid Inheritance p. 148 Order of Invocation of Constructors and Destructors p. 149 Virtual Functions and Dynamic Polymorphism p. 153
Need for Virtual Functions p. 153 Virtual Functions p. 156 Mechanism of Virtual Functions p. 160 Pure Virtual Functions p. 162 Virtual Destructors and Virtual Constructors p. 167 Virtual Destructors p. 167 Virtual Constructors p. 168 Stream and File Handling p. 172 Streams p. 172 Class Hierarchy for Handling Streams p. 172 Text and Binary Input/Output p. 174 Data Storage in Memory p. 174 Input/Output of Character Data p. 175 Input/Output of Numeric Data p. 175 Note on Opening Disk Files for I/O p. 176 Text Versus Binary Files p. 176 Text Output/Input p. 177 Text Output p. 177 Text Input p. 181 Binary Output/Input p. 185 Binary Output-write () Function p. 185 Binary Input-read () Function p. 189 Opening and Closing Files p. 193 open() Function p. 193 close() Function p. 194 Files as Objects of the fstream Class p. 194 File Pointers p. 194 seekp() Function p. 195 tellp() Function p. 196 seekg() Function p. 196 tellg() Function p. 196 Random Access to Files p. 197 Object Input/Output Through Member Functions p. 197 Error Handling p. 199 eof() Function p. 199 fail() Function p. 199 bad() Function p. 200 clear() Function p. 200 Manipulators p. 201 Pre-defined Manipulators p. 201 User-defined Manipulators p. 203
Command Line Arguments p. 204 Operator Overloading, Type Conversion, New Style Casts, and RTTI p. 211 Operator Overloading p. 211 Overloading Operators-The Syntax p. 212 Compiler Interpretation of Operator-Overloading Functions p. 214 Overview of Overloading Unary and Binary Operators p. 216 Operator Overloading p. 216 Rules for Operator Overloading p. 219 Overloading Various Operators p. 221 Overloading Increment and Decrement Operators (Prefix and Postfix) p. 221 Overloading Unary Minus and Unary Plus Operator p. 224 Overloading Arithmetic Operators p. 225 Overloading Relational Operators p. 230 Overloading Assignment Operator p. 234 Overloading Insertion and Extraction Operators p. 240 Overloading new and delete Operators p. 244 Overloading Subscript Operator p. 261 Overloading Pointer-to-member (->) Operator (Smart Pointer) p. 265 Type Conversion p. 267 Basic Type to Class Type p. 267 Class Type to Basic Type p. 268 Class Type to Class Type p. 269 New Style Casts and the typeid Operator p. 271 dynamic_cast Operator p. 271 static_cast Operator p. 275 reinterpret_cast Operator p. 276 const_cast Operator p. 276 typeid Operator p. 277 Data Structures p. 283 Introduction p. 283 Linked Lists p. 284 Stacks p. 336 Queues p. 340 Trees p. 343 Binary Trees p. 344 Binary Search Trees p. 347 Templates p. 372 Introduction p. 372 Function Templates p. 373 Class Templates p. 378 Nested Class Templates p. 382
Standard Template Library p. 382 list Class p. 383 vector Class p. 386 pair Class p. 387 map Class p. 387 set Class p. 389 multimap Class p. 389 multiset Class p. 390 Exception Handling p. 393 Introduction p. 393 C-Style Handling of Error-generating Code p. 394 Terminate the Program p. 394 Check the Parameters before Function Call p. 395 Return a Value Representing an Error p. 396 C++-Style Solution-the try/throw/catch Construct p. 397 It is Necessary to Catch Exceptions p. 400 Unwinding of the Stack p. 401 Need to Throw Class Objects p. 404 Accessing the Thrown Object in the Catch Block p. 406 Throwing Parameterized Objects of a Nested Exception Class p. 408 Catching Uncaught Exceptions p. 409 Re-throwing Exceptions p. 410 Limitation of Exception Handling p. 414 Case Study-A Word Query System p. 417 Problem Statement p. 417 A Sample Run p. 417 The Source Code p. 418 Explanation of the Code p. 420 Comparison of C++ with C p. 425 Non-object-oriented Features Provided in C++ that are Absent in C Language p. 425 Object-oriented Features Provided in C++ to make it Comply with the Requirements of the p. 426 Object-Oriented Programming System Comparison of C++ with Java p. 427 Similarities between C++ and Java p. 427 Differences between C++ and Java p. 428 Object-Oriented Analysis and Design p. 437 Introduction p. 437 Why Build Models? p. 437 Overview of OOAD p. 437 Object-Oriented Model p. 438 Object Model p. 438 Dynamic Model p. 442
Functional Model p. 444 Analysis p. 446 Overview of Analysis p. 446 Object Modelling p. 446 Dynamic Modelling p. 446 Functional Modelling p. 447 System Design p. 447 Breaking the System into Sub-systems p. 447 Layers p. 447 Partitions p. 447 Object Design p. 448 Overview of Object Design p. 448 Implementation p. 448 Glossary p. 449 Self Tests p. 454 p. 454 p. 456 p. 458 Bibliography p. 460 Index p. 461 Table of Contents provided by Blackwell's Book Services and R.R. Bowker. Used with permission.