C++ Annotations Version 4.3.1a

C++ Annotations Version 4.3.1a

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 - 1998

This document is intended for knowledgeable users of C who would like to make the transition to C++. It is a guide for Frank's 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. If you want a hard-copy version of the C/C++ annotations: that's available in postscript, and other formats in our ftp-site.



Chapter 1: Overview of the chapters

Chapter 2: Introduction

2.0.1: History of the C++ Annotations

2.1: What's new in the C++ Annotations

2.2: The history of C++

2.2.1: Compiling a C program by a C++ compiler

2.3: Advantages and pretensions of C++

2.4: What is Object-Oriented Programming?

2.5: Differences between C and C++

2.5.1: End-of-line comment

2.5.2: NULL-pointers vs. 0-pointers

2.5.3: Strict type checking

2.5.4: The void argument list

2.5.5: The #define __cplusplus

2.5.6: The usage of standard C functions

2.5.7: Header files for both C and C++

2.5.8: The definition of local variables

2.5.9: Function Overloading

2.5.10: Default function arguments

2.5.11: The keyword typedef

2.5.12: Functions as part of a struct

Chapter 3: A first impression of C++

3.1: More extensions of C in C++

3.1.1: The scope operator ::

3.1.2: cout, cin and cerr

3.1.3: The `bool' data type

3.1.4: The `wchar_t' data type

3.1.5: The keyword const

3.1.6: 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.2: Const member functions and const objects

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 declarations

4.4.2: Inline functions outside of class declarations

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

4.7: Header file organization with 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: The this pointer

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: The IO-stream Library

9.1: Iostreams: insertion (<<) and extraction (>>)

9.1.1: The insertion operator <<

9.1.2: The extraction operator >>

9.2: Four standard iostreams

9.3: Files in general

9.3.1: Writing streams

9.3.2: Reading streams

9.3.3: Reading and writing streams

9.3.4: IOStream Condition States

9.3.5: Special functions

9.3.6: Formatting

9.3.6.1: The (v)form() and (v)scan() members

9.3.6.2: Format states: dec, hex, oct manipulators

9.3.6.3: Setting the precision: the member precision()

9.3.6.4: Setting the display form: the member setf()

9.3.6.5: The manipulator setw()

9.3.6.6: String Formatting

Chapter 10: More about friends

10.1: Inserting String objects into streams

10.2: An initial solution

10.3: Friend-functions

10.3.1: Preventing the friend-keyword

10.4: Friend classes

Chapter 11: Inheritance

11.1: Related types

11.2: The constructor of a derived class

11.3: The destructor of a derived class

11.4: Redefining member functions

11.5: Multiple inheritance

11.6: Conversions between base classes and derived classes

11.6.1: Conversions in object assignments

11.6.2: Conversions in pointer assignments

11.7: Storing base class pointers

Chapter 12: Polymorphism, late binding and virtual functions

12.1: Virtual functions

12.1.1: Polymorphism in program development

12.1.2: How polymorphism is implemented

12.2: Pure virtual functions

12.3: Comparing only Persons

12.4: Virtual destructors

12.5: Virtual functions in multiple inheritance

12.5.1: Ambiguity in multiple inheritance

12.5.2: Virtual base classes

12.5.3: When virtual derivation is not appropriate

Chapter 13: Exceptions

13.1: Using exceptions: an outline

13.1.1: Compiling sources in which exceptions are used

13.2: An example using exceptions

13.2.1: No exceptions: the setjmp() and longjmp() approach

13.2.2: Exceptions: the preferred alternative

13.3: Throwing exceptions

13.3.1: The empty throw statement

13.4: The try block

13.5: Catching exceptions

13.5.1: The default catcher

13.6: Declaring exception throwers

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: The class Storable

15.1.2.1: Converting an existing class to a Storable

15.1.3: The class Storage

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.2.3: Using Tree and Node

15.3: Classes to process program options

15.3.1: Functionality of the class Configuration

15.3.1.1: The interface of the class Configuration

15.3.1.2: An example of a program using the class Configuration

15.3.2: Implementation of the class Configuration

15.3.2.1: The constructor

15.3.2.2: loadResourceFile()

15.3.2.3: loadCommandLineOptions()

15.3.3: The class Option

15.3.3.1: The interface of the class Option

15.3.3.2: The static member nextOptionDefinition

15.3.4: Derived from Option: The class TextOption

15.3.4.1: The interface of the class TextOption

15.3.4.2: The implementation of the assign() function

15.3.5: The class Object

15.3.6: The class Hashtable

15.3.6.1: The Hashtable constructor

15.3.6.2: The function mayInsert()

15.3.6.3: The function expanded()

15.3.7: Auxiliary classes

15.3.7.1: The class Mem

15.3.7.2: The class String

15.3.7.3: The class StringTokenizer

15.3.7.4: The class Ustream

15.3.7.5: The class Util

15.4: Using Bison and Flex

15.4.1: Using Flex++ to create a scanner

15.4.1.1: The flex++ specification file

15.4.1.2: The derived class: Scanner

15.4.1.3: The main() function

15.4.1.4: Building the scanner-program

15.4.2: Using both bison++ and flex++

15.4.2.1: The bison++ specification file

15.4.2.2: The bison++ token section

15.4.2.3: The bison++ grammar rules

15.4.2.4: The flex++ specification file

15.4.2.5: The generation of the code