C++ Annotations
Version 4.0.0
C++ Annotations
Version 4.0.0
Frank B. Brokken and Karel Kubat
ICCE, University of Groningen
Westerhaven 16, 9718 AW Groningen
Netherlands
Published at the University of Groningen
ISBN 90 367 0470 7
1994 - 1997
This document is intended for knowledgable users of C who would
like to make the transition to C++. It is a guide for our C/C++
programming
courses, which are given yearly at the University of Groningen. As such,
this document is not a complete C/C++ handbook. Rather, it serves as
an addition to other documentation sources.
The current version is 4.0.0, being a major rewrite of the previous
version 3.4.14: The document was rewritten from SGML to
Yodl, and many
new sections were added. All sections got a tune-up. The distribution basis,
however, hasn't changed a bit: see the introduction.
Note that this version (4.0.0) is a preliminary release, that may
change on a daily basis. The text and postscript versions of this document
aren't available yet.
The version you're reading now has been compiled on Sat Jun 7 20:48:38 MET DST 1997.
Chapter 2: Introduction to C++
2.1: The history of C++
2.1.1: Compiling a C program by a C++ compiler
2.2: Advantages and pretensions of C++
2.3: What is Object-Oriented Programming?
2.4: Differences between C and C++
2.4.1: End-of-line comment
2.4.2: NULL-pointers vs. 0-pointers
2.4.3: Strict type checking
2.4.4: The void argument list
2.4.5: The #define __cplusplus
2.4.6: The usage of standard C functions
2.4.7: Header files for both C and C++
2.4.8: The definition of local variables
2.4.9: The scope operator ::
2.4.10: Function Overloading
2.4.11: Default function arguments
2.4.12: The keyword typedef
2.4.13: Functions as part of a struct
Chapter 3: A first impression of C++
3.1: More extensions of C in C++
3.1.1: cout, cin and cerr
3.1.2: The keyword const
3.1.3: References
3.2: Functions as part of structs
3.3: Data hiding: public, private and class
3.4: Structs in C vs. structs in C++
Chapter 4: Classes
4.1: Constructors and destructors
4.1.1: The constructor
4.1.2: The destructor
4.1.3: A first application
4.1.4: Constructors with arguments
4.1.4.1: The order of construction
4.3: The operators new and delete
4.3.1: Allocating and deallocating arrays
4.3.2: New and delete and object pointers
4.3.3: The function set_new_handler()
4.4: The keyword inline
4.4.1: Inline functions within class definitions
4.4.2: Inline functions outside of class definitions
4.4.3: When to use inline functions
4.5: Objects in objects: composition
4.5.1: Composition and const objects: const member initializers
4.5.2: Composition and reference objects: reference member initializers
4.6: Friend functions and friend classes
Chapter 5: Classes and memory allocation
5.1: Classes with pointer data members
5.2: The assignment operator
5.2.1: Overloading the assignment operator
5.2.1.1: The function 'operator=()'
5.3.1: Preventing self-destruction with this
5.3.2: Associativity of operators and this
5.4: The copy constructor: Initialization vs. Assignment
5.4.1: Similarities between the copy constructor and operator=()
5.5: Conclusion
Chapter 6: More About Operator Overloading
6.1: Overloading operator[]()
6.2: Overloading operator new(size_t)
6.3: Overloading operator delete(void *)
6.4: Cin, cout, cerr and their operators
6.5: Conversion operators
6.6: Overloadable Operators
Chapter 7: Static data and functions
7.1: Static data
7.1.1: Private static data
7.1.2: Public static data
7.2: Static member functions
Chapter 8: Classes having pointers to members
8.1: Pointers to members: an example
8.2: Initializing pointers to members
8.3: Pointers to static members
8.4: Using pointers to members for real
8.4.1: Pointers to members: an implementation
Chapter 9: More about friends
9.1: Inerting String objects into streams
9.2: An initial solution
9.3: Friend-functions
9.3.1: Preventing the friend-keyword
9.4: Friend classes
Chapter 10: Inheritance
10.1: Related types
10.2: The constructor of a derived class
10.3: Redefining member functions
10.4: Multiple inheritance
10.5: Conversions between base classes and derived classes
10.5.1: Conversions in object assignments
10.5.2: Conversions in pointer assignments
10.6: Storing base class pointers
Chapter 11: Polymorphism, late binding and virtual functions
11.1: Virtual functions
11.1.1: Polymorphism in program development
11.1.2: How polymorphism is implemented
11.2: Pure virtual functions
11.3: Comparing only Persons
11.4: Virtual destructors
11.5: Virtual functions in multiple inheritance
11.5.1: Ambiguity in multiple inheritance
11.5.2: Virtual base classes
11.5.3: When virtual derivation is not appropriate
Chapter 12: The IO-stream Library
12.1: Iostreams: insertion (<<) and extraction (>>)
12.1.1: The insertion operator <<
12.1.2: The extraction operator >>
12.2: Four standard iostreams
12.3: Files in general
12.3.1: Writing streams
12.3.2: Reading streams
12.3.3: Reading and writing streams
12.3.4: IOStream Condition States
12.3.5: Special functions
12.3.6: Formatting
12.3.6.1: The function format()
12.3.6.2: Format states
12.3.6.3: The function precision()
12.3.6.4: The function setw()
Chapter 13: Exceptions
13.1: Throwing exceptions
13.1.1: The empty throw statement
13.2: The try block
13.3: Catching exceptions
13.3.1: The default catcher
13.4: Declaring exception throwers in header files
Chapter 14: Templates
14.1: Template functions
14.2: Template classes
14.2.1: A template class: Array
14.2.2: Using the Array class
14.3: Templates and Exceptions
14.4: Evaluation of template classes
Chapter 15: Concrete examples of C++
15.1: Storing objects: Storable and Storage
15.1.1: The global setup
15.1.1.1: Interface functions of the class Storage
15.1.1.2: To copy or not to copy?
15.1.1.3: Who makes the copy?
15.1.2.1: Converting an existing class to a Storable
15.2: A binary tree
15.2.1: The Node class
15.2.2: The Tree class
15.2.2.1: The `standard' functions
15.2.2.2: Adding an object to the tree
15.2.2.3: Scanning the tree
15.2.2.4: The primitive operations copy() and destroy()
15.3: Using Bison and Flex
15.3.1: Using Flex++ to create a scanner
15.3.1.1: The flex++ specification file
15.3.1.2: The derived class: Scanner
15.3.1.3: The main() function
15.3.1.4: Building the scanner-program
15.3.2.1: The bison++ specification file
15.3.2.2: The bison++ token section
15.3.2.3: The bison++ grammar rules