Introduction:

In this section, we will introduce you to all the perverse features of C++ that no one bothers to cover in the body of other text books (not to say that we did either). For examples of the topics we will cover, look over:

the overload of the assignment operator ( operator= ) returns a *this pointer (basic);
contains examples of Unicode strings (intermediate);
uses typeid() to determine correct methods to call (advanced).


You won't find information on these points in a concise location in the Lippman and Lajoie text, but the locations at which the topics in this section are discussed follow the text of each section.

The *this Pointer:

The self-referencing *this pointer can be used to access the memory location of the object that made the function call. In this example, the function call will be implicit. Operators such as the assignment operator (=) should return the memory location of the modified object on the left side of the operator. An example of returning *this in the Boolean class looks like this: Returning *this from the assignment operator returns a memory reference to re-assigned variable while the actual assigning takes place in the function body. For more information on *this (pardon the pun), see Lippman and Lajoie, Section 13.4.

Typeid:

How do you write code to operate on a class without knowing the identity of the class? This is a problem we all face with data-driven programming. How do you process an object read from the disk when you don't know the object's type until you have read it? You could write a big if-else-if chunk of code, but such code isn't very portable or extensible.

Instead, we use the typeid() method from the typeinfo library to determine whether the classes assigned to a template are valid for use in that template. Typeid returns the type of the object passed to it. This is useful if you want to find out what kind of object was passed to a template from inside the template. To use typeid, you must first include the typeinfo header file: Once typeinfo is included, you can find unknown types by calling typeid() and passing it the objects whose type you wish to determine: For more infomation on typeid and the typeinfo library, see Lippman and Lajoie, Section 19.1.2.

Unicode:

Our next somewhat obscure feature is Unicode support. Unicode provides for characters that are twice as wide as ANSI standard chararacters. This extra bit-space provides room to store the information for character sets, such as Chinese, that need much larger storage units than English's Arabic characters. Strings and characters are forced to be Unicode characters by placing a capital L just before the open quotes of the string literals: Our software environment uses Unicode characters from the ground up, so our speech recognition system is compatible with any spoken language that is supported within the Unicode system. We do not use the setlocale mechanisms previously suggested in ANSI C to support different encoding systems.

For more information on wide characters, see Lippman and Lajoie, Section 3.1.0.

Iostream:

Use of the final obscure feature of this tutorial is not really obscure, though it is taboo in ISIP. This feature is the iostream library. We generally believe iostream is unreliable in cross-platform applications, and it has been problematic over the years with respect to compiler support. More importantly, we have our own I/O methods built into the Sof class, which provide an elegant way to move data to and from files. We have spent a great deal of effort supporting formatted I/O in the environment, with the goal of reducing this burden on the user. There should be no need to use the iostream class.

Function Template Instantiation:

Basically, there are two kinds of compilation models for template, Inclusion Compilation Model and Seperation Compilation Model. Under the inclusion compilation model, we include the definition of the function template in every file in which a template is instantiated, usually by placing the definition within a header file as we do with inline functions. When we use the inclusion compilation model, we include Sof class, which provide an elegant way to move data to and from files.

If you would like to learn about the iostream class, see Lippman and Lajoie, Chapter 20.