Written for the moderately experienced Java programmer, this book builds on readers� existing knowledge of object-oriented programming and covers all important aspects of Standard C++--emphasizing more lower-level C-style details later in the presentation. KEY TOPICS: Chapter topics include philosophy of C++, simplest C++, pointers and reference variables, object-based programming: classes, operator overloading, object-oriented programming: inheritance, templates, abnormal control flow, input and output, collections: the standard template library, primitive arrays and strings, C-style C++, and using Java and C++: the JNI. MARKET: For new C++ programmers converted from Java. Contents Preface Introduction High Level Differences Ten Reasons To Use C++ Key Points Chapter1 Basic Types and Control Structures 1.1 First Program 1.2 Primitive Types 1.2.1 Integer Types 1.2.2 Floating Point Types 1.2.3 character Type 1.2.4 Boolean Type 1.3 Syntactic Differences 1.3.1 Operators and Expressions 1.3.2 Conditionals 1.3.3 Loops 1.3.4 Definite Assignment 1.4 Additional Syntax 1.4.1 Primitive Type Casts 1.4.2 Labels 1.4.3 typedef Statement 1.5 Key Points Chapter2 Functions, Arrays, Strings and Parameter Passing 2.1 Functions 2.1.1 Function definition 2.1.2 Function Invocation 2.1.3 Function overloading 2.1.4 Function Declaractions 2.1.5 Default Parameters 2.1.6 Inline Functions 2.1.7 Separate Compilation 2.2 Arrays and Strings 2.2.1 Using the vector Library Type 2.2.2 Using the string Library Type 2.2.3 Arrays of Objects 2.2.4 Primitive Arrays of Constants 2.2.5 Multidimensional Arrays 2.3 Parameter Passing 2.3.1 Call by Reference 2.3.2 Call by Constant Reference 2.3.3 Parameter Passing Summary 2.4 Key Points Chapter3 Pointers and Reference Variables 3.1 Java vs. C++ Memory Model 3.2 Pointers 3.3 Memory Heap Management 3.3.1 The new Operator 3.3.2 Garbage collection and delete operator 3.3.3 Stale pointers 3.3.4 Double-delete 3.3.5 Functions that Return Pointers 3.4 The->Operator 3.5 Reference Variables 3.6 Uses and Abuses of Pointer Variables 3.6.1 Parameter Passing:Simulating Call-By-Reference 3.6.2 Arrays and Strings 3.6.3 Avoiding Large Data Movements 3.6.4 Linked Data Structures 3.6.5 Inheritance Chapter4 Object-Based Programming: Classes 4.1 Similarities, Modulo Syntax 4.2 Accessors vs. Mutators 4.3 The explicit Keyword 4.4 Why C++ Needs More Syntex Than Java 4.5 Initializer Lists 4.6 The Big Three: Destructor, Copy Constructor, and operator= 4.6.1 Destructor 4.6.2 Copy Constructor 4.6.3 operator= 4.6.4 Issues Concerning the Defaults 4.6.5 When the Defaults Do Not Work 4.6.6 Linked Data Structures 4.6.7 Default Consructor 4.6.8 Disabling Copying 4.7 Friends 4.7.1 Classes as friends 4.7.2 Methods as friends 4.8 Nested Classes 4.9 The struct Type 4.10 Return By Constant Reference Revisited 4.11 Separation of Interface and Implementation 4.12 #ifndef and #endif 4.13 Static Members 4.14 Anonymous Objects 4.15 Namespaces 4.16 Incomplete Class Declaration 4.17 Technical Differences 4.17.1 Member Functions and Data Members Cannot Have Same Name 4.17.2 Inline Data Member Initialization 4.17.3 Default Data Member Initialization 4.17.4 Default Visibility 4.18 Key Points 4.19 Exercises Chapter5 Operator Overloading 5.1 Basics of Operator Overloading 5.2 Overloading I/O 5.3 Global vs. Class Operators 5.4 What Can Be Overloaded? 5.5 A Rational Number Class 5.5.1 Assignment Operators 5.5.2 Arithmetic Operators 5.5.3 Relational and Equality Operators 5.5.4 Input and Output Operators 5.5.5 Unary Operators 5.6 Matrix Class (for doubles) 5.7 Liabilities of Operator Overloading 5.8 Key Points 5.9 Exercises Chapter6 Object-Oriented Programming: Inheritance 6.1 Basic Syntax 6.2 Dynamic Dispatch 6.3 Constructors, the Big Three and Inheritance 6.3.1 Defaults 6.3.2 Implementing the Big-Three Explicitly 6.3.3 Virtual Destructor 6.4 Abstract Methods and Classes 6.5 Slicing 6.6 Why Inheritance Is Harder In C++ Than Java 6.7 Type Conversions 6.8 Multiple Inheritance and Interfaces 6.9 Protected and Friends 6.10 Technical Differences 6.10.1 No Root Class 6.10.2 Non-Public Inheritance 6.10.3 Reducing Visibility When Overriding 6.10.4 New Methods Hide Originals in Base Classes 6.10.5 Overriding With Different Return Type 6.10.6 Type Compatibility 6.10.7 Reflection 6.10.8 Dynamic Dispatch in Constructors 6.10.9 Default Parameters 6.11 Key Points 6.12 Exercises Chapter7 Templates 7.1 Review of Generic Programming in Java 7.2 Function Templates 7.3 Class Templates 7.4 Separate Compilation 7.4.1 Everything in the Header 7.4.2 Explicit Instantiation 7.4.3 The export Directive 7.5 Specialized Templates 7.5.1 Multiple Template Parameters 7.5.2 Template Nontype Parameters 7.5.3 Default Template Parameters 7.5.4 Member Templates 7.6 Templates for Function Objects 7.6.1 The Java Solution 7.6.2 Avoiding Inheritance 7.6.3 Function Objects With operator() 7.7 Key Points 7.8 Exercises Chapter8 Abnormal Control Flow 8.1 The Design of C++ 8.2 Non-Exception Error Handling 8.2.1 abort and exit 8.2.2 Assertions 8.2.3 Error states 8.3 Exception Handling 8.3.1 Basic syntax 8.3.2 No finally clause 8.3.3 The Throw List and Unexpected Exceptions 8.3.4 Missing Throw List 8.3.5 What Can Be Thrown 8.3.6 Standard Exception Classes 8.3.7 Rethrowing Exceptions 8.3.8 Catching All Exceptions 8.3.9 Inheritance and Exceptions 8.3.10 Templates and Exceptions 8.4 The auto_ptr Class 8.5 Key Points 8.6 Exercises Chapter9 Input and Output 9.1 The Basic Hierarchy 9.2 Error States 9.3 Output 9.4 Input 9.5 Files 9.6 Random Access 9.7 String Streams 9.8 endl 9.9 Serialization 9.10 Key Points 9.11 Exercises Chapter10 Collections: The Standard Template Library 10.1 Containers and Iterators 10.1.1 Containers 10.1.2 Iterators 10.1.3 Pairs 10.1.4 Inheritance and Containers 10.1.5 Constructors 10.2 Sequence Containers: vector and list 10.3 Error Checks in the STL 10.4 Other Iterators 10.4.1 Reverse Iterators 10.4.2 Stream Iterators 10.5 Stacks and Queues 10.6 Sets 10.6.1 Standard Function Objects 10.6.2 set Operations 10.6.3 multisets 10.6.4 Using Function Objects to Change Default Ordering 10.7 Maps 10.7.1 Multimaps 10.8 STL Example 10.9 Priority Queue 10.10 Generic Algorithms 10.10.1 Sorting 10.10.2 Searching 10.10.3 Unary Binder Adapters 10.10.4 Copying 10.10.5 Inserter Adapters 10.11BitSets 10.12Key Points 10.13Exercises Chapter11 Primitive Arrays and Strings 11.1 Primitive Arrays 11.1.1 The C++ Implementation: An Array Name Is a Pointer 11.1.2 Dynamic Allocation of Arrays 11.2 Primitive Strings 11.3 Pointer Hopping 11.3.1 Implications of the Precedence of *, &, and [] 11.3.2 What Pointer Arithmetic Means 11.3.3 A Pointer-Hopping Example 11.3.4 Is Pointer Hopping Worthwhile? 11.4 Primitive Arrays and the STL 11.5 Command-Line Arguments 11.6 Primitive Multidimensional Arrays 11.7 Key Points 11.8 Exercises Chapter12 C-Style C++ 12.1 Preprocessor Macros 12.1.1 Simple Textual Substitution 12.1.2 Parameterized Macros 12.2 Unsafe Casts 12.3 C-Style Parameter Passing 12.4 C Library Routines 12.4.1 printf and scanf 12.4.2 File I/O 12.4.3 malloc, calloc, realloc, and free 12.4.4 atoi, atof, strtol, and strtod 12.4.5 system 12.4.6 qsort 12.4.7 Variable Number of Arguments 12.5 C Programming 12.6 Key Points 12.7 Exercises Chapter13 Using Java and C++: The JNI 13.1 JNI Basics 13.2 Implementing A Simple Parameter-less, Return-less Method 13.2.1 Compiling a Shared Library 13.3 JNI Types 13.4 Accessing Java Objects 13.4.1 Accessing Fields 13.4.2 Invoking Methods 13.4.3 Invoking Constructors 13.5 Strings and Arrays 13.5.1 Strings 13.5.2 Arrays 13.6 Using Java Exceptions 13.7 Using C Instead of C++ 13.8 JNI References 13.9 Java Monitors 13.10Invocation API 13.11Key Points 13.12Exercises Bibliography Index
For experienced Java programmers and students who require the skills of C++ programming, best-selling author Mark Allen Weiss bridges the gap. He efficiently presents the complex C++ language in this well-designed tutorial/reference that both students and seasoned programmers will appreciate. The book is ideal as a primary text for intermediate C++ courses, as a supplemental no-nonsense reference for other courses, or for independent learning by professionals.
C++ for Java Programmers is a concise, well-written text that provides authoritative and up-to-date coverage of key features and details of C++, with a special focus on how C++ compares to Java. The book's approach shows knowledgeable students or professionals how to grasp the complexities of C++ and harness its power by mutually addressing the benefits and the pitfalls of the two languages. By highlighting the features and comparative elements of each language, and building on the reader's existing knowledge of object-oriented programming, C++ for Java Programmers enables users to master the essentials of C++ quickly and thoroughly.
Key Features
- Includes insightful comparisons of the two programming languages throughout the text and points out the subtleties of C++
- Succinctly covers the pertinent highlights of STL (Standard Template Library) and the most effective use of templates
- Explains the use of the powerful JNI (Java Native Interface) for combining Java and C++
- Includes a summary of key C++ features and issues with each chapter
- Provides extensive treatment of C details the programmer is likely to encounter in C++
- Companion Website for complete online source code at:
http://www.prenhall.com/weiss - Available Instructors Resource CD-ROM
For courses in C++ Intermediate Programming. Best selling author Mark Allen Weiss wrote this book as a concise no-nonsense introduction to C++ for experienced programmers learning a second language or for use as a supplemental reference in C++ based courses such as data structures. The book could be used as a primary textbook for moderately experienced Java programmers who need a concise and authoritative tutorial/reference to C++. He builds on students existing knowledge of Java programming and Weiss covers all important aspects of the complex C++ language in under 300 pages. Written for the moderately experienced Java programmer, this text builds on students' existing knowledge of object-oriented programming and covers all important aspects of standard C++ - emphasizing more lower-level C-style details later in the presentation.