APPENDIX B Glossary
Special Characters
& has a number of distinct meanings. When it precedes the name of a variable without following the name of a type, it means "the address of the following variable". For example, &Str means "the address of the variable Str". When & follows a type name and precedes a variable name, it means that the variable being declared is a reference - that is, another name for a preexisting variable. In this book, references are used only in argument lists, where they indicate that the variable being defined is a new name for the caller's variable rather than a new local variable.
% is the "modulus" operator, which returns the remainder after dividing its left-hand argument by its right-hand argument.
:: is the scope resolution operator, which is used to tell the compiler the scope of a variable. We can prefix it to the name of a global variable to prevent the compiler from confusing it with a variable of the same name from the standard library. It is also used to specify the namespace or class of a variable or function, when placed between the namespace or class name and the variable or function name.
< is the "less than" operator, which returns the value true if the expression on its left has a lower value than the expression on its right; otherwise, it returns the value false. Also see operator < in the index.
<< is the "stream output" operator, used to write data to an ostream. Also see operator << in the index.1
<= is the "less than or equal to" operator, which returns the value true if the expression on its left has the same or a lower value than the expression on its right; otherwise, it returns the value false. Also see operator <= in the index.
= is the assignment operator, which assigns the value on its right to the variable on its left. Also see operator = in the index.
== is the "equals" operator, which returns the value true if the expression on its left has the same value as the expression on its right; otherwise, it returns the value false. Also see operator == in the index.
> is the "greater than" operator, which returns the value true if the expression on its left has a greater value than the expression on its right; otherwise, it returns the value false. Also see operator > in the index.
>= is the "greater than or equal to" operator, which returns the value true if the expression on its left has the same or a greater value than the expression on its right; otherwise, it returns the value false. Also see operator >= in the index.
>> is the "stream input" operator, used to read data from an istream. Also see operator >> in the index.
[ ] is used after the delete operator to tell the compiler that the pointer for which delete was called refers to a group of elements rather than just one data item, e.g., when deleting an array of chars. This is one of the few times when we have to make that distinction explicitly rather than leaving it to context.
!= is the "not equals" operator, which returns the value true if the expression on its left has a value different from the expression on its right; otherwise, it returns the value false. Also see operator != in the index.
&& is the "logical AND" operator. It produces the result true if the expressions on both its right and left are true; if either of those expressions is false, it produces the result false. However, this isn't the whole story. There is a special rule in C++ governing the execution of the && operator: If the expression on the left is false, then the answer must be false and the expression on the right is not executed at all. The reason for this short-circuit evaluation rule is that in some cases you may want to write a right-hand expression that will only be valid if the left-hand expression is true.
+= is the "add to variable" operator, which adds the value on its right to the variable on its left.
-= is the "subtract from variable" operator, which subtracts the value on its right from the variable on its left.
|| is the "logical OR" operator. It produces the result true if at least one of the two expressions on its right and left is true; if both expressions are false, it produces the result false. However, there is a special rule in C++ governing the execution of the || operator: if the expression on the left is true, then the answer must be true and the expression on the right is not executed at all. The reason for this short-circuit evaluation rule is that in some cases you may want to write a right-hand expression that will only be valid if the left-hand expression is false.
A #define statement is a preprocessor directive that defines a preprocessor symbol. While this statement can be used to define constant values for general use, it has been mostly superseded except as part of the include guard mechanism.
An #endif statement is a preprocessor directive that terminates a section of conditional code. It is used in this book as part of the include guard mechanism.
An #ifdef statement is a preprocessor directive that begins a section of conditional code. It has the opposite effect from the #ifndef directive.
An #ifndef statement is a preprocessor directive that tells the preprocessor to check whether a particular preprocessor symbol has been defined. If not, the following source code is treated normally. However, if the specified preprocessor symbol has been defined, the following source code is skipped by the rest of the compiler as though it were not present in the source file. The #ifndef statement is used in this book as part of the include guard mechanism.
An #include statement is a preprocessor directive that has the same effect as that of copying all of the code from a specified file into another file at the point where the #include statement is written. For example, if we wanted to use definitions contained in a file called xstream.h in the implementation file test.cpp, we could insert the include statement #include "xstream.h" in test.cpp rather than physically copying the lines from the file xstream.h into test.cpp.
A
An access specifier controls the access of nonmember functions to the member functions and variables of a class. The C++ access specifiers are public, private, and protected. See public, private, and protected for details. Also see friend.
Access time is a measure of how long it takes to retrieve data from a storage device, such as a hard disk or RAM.
An algorithm is a set of precisely defined steps guaranteed to arrive at an answer to a problem or set of problems. As this implies, a set of steps that might never end is not an algorithm in the strictest sense.
Aliasing is the practice of referring to one object by more than one "name"; in C++, these names are actually pointers or references.
An application program is a program that actually accomplishes some useful or interesting task. Examples include inventory control, payroll, and games.
An application programmer (or class user) is a programmer who uses native and class variables to write an application program. Also see library designer.
An argument is a value supplied by one function (the calling function) that wishes to make use of the services of another function (the called function). There are two main types of arguments: value arguments, which are copies of the values from the calling function, and reference arguments, which are not copies but actually refer to variables in the calling function.
An argument list is a set of argument definitions specified in a function declaration. The argument list describes the types and names of all the variables the function receives when it is called by a calling function.
An array is a group of elements of the same type - for example, an array of chars. The array name corresponds to the address of the first of these elements; the other elements follow the first one immediately in memory. As with a vector, we can refer to the individual elements by their indexes. Thus, if we have an array of chars called m_Data, m_Data[i] refers to the ith char in the array. Also see pointer, vector.
An array initialization list is a list of values used to initialize the elements of an array. The ability to specify a list of values for an array is built into the C++ language and is not available for user-defined data types such as the vector.
The ASCII code is a standardized representation of characters by binary or hexadecimal values. For example, the letter "A" is represented as a char with the hexadecimal value 41, and the digit 0 is represented as a char with the hexadecimal value 30. All other printable characters also have representations in the ASCII code.
Assignment is the operation of setting a variable to a value. The operator that indicates assignment is the equal sign, =. Also see operator = in the index.
An assignment operator is a function that sets a preexisting variable to a value of the same type. There are three varieties of assignment operators:
- 1. For a variable of a native type, the compiler supplies a native assignment operator.
- 2. For a variable of a class type, the compiler generates its own version of an assignment operator (a compiler-generated assignment operator) if the class writer does not write one.
- 3. The class writer can write a member function (a user-defined assignment operator) to do the assignment; see operator = in the index.
An assignment statement such as x = 5; is not an algebraic equality, no matter how much it may resemble one. It is a command telling the compiler to assign a value to a variable. In the example, the variable is x and the value is 5.
The auto storage class is the default storage class for variables declared within C++ functions. When we define a variable of the auto storage class, its memory address is assigned automatically upon entry to the function where it is defined; the memory address is valid for the duration of that function.
Automatic conversion is a feature of C++ that allows an expression of one type to be used where another type is expected. For example, a short variable or expression can be provided when an int expression is expected, and the compiler will convert the type of the expression automatically.
B
A base class initializer specifies which base class constructor we want to use to initialize the base class part of a derived class object. It is one of the two types of expressions allowed in a member initialization list. Also see inheritance, constructor.
The base class part of a derived class object is an unnamed component of the derived class object whose member variables and functions are accessible as though they were defined in the derived class, so long as they are either public or protected.
A batch file is a text file that directs the execution of a number of programs, one after the other, without manual intervention. A similar facility is available in most operating systems.
A bit is the fundamental unit of storage in a modern computer; the word bit is derived from the phrase binary digit. Each bit, as this suggests, can have one of two states: 0 and 1.
A block is a group of statements considered as one logical statement. It is delimited by the curly braces, { and }. The first of these symbols starts a block, and the second one ends it. A block can be used anywhere that a statement can be used and is treated exactly as if it were one statement. For example, if a block is the controlled block of an if statement, all of the statements in the block are executed if the condition in the if is true, and none is executed if the condition in the if is false.
A bool (short for Boolean) is a type of variable whose range of values is limited to true or false. This is the most appropriate return type for a function that uses its return value to report whether some condition exists, such as operator <. In that particular case, the return value true indicates that the first argument is less than the second, while false indicates that the first argument is not less than the second.
A break statement is a loop control device that interrupts the processing of a loop whenever it is executed within the controlled block of a loop control statement. When a break statement is executed, the flow of control passes to the next statement after the end of the controlled block.
A byte is the unit in which data capacities are stated, whether in RAM or on a disk. In most modern computers, a byte consists of eight bits.
C
A C function is one that is inherited from the C library. Because C does not have a number of features that have been added in C++, such as function overloading and reference arguments, C functions must often be called in different ways from those we use when calling a C++ function.
The C standard library is a part of the C++ standard library. It consists of a collection of functions that were originally written for users of the C programming language. Because C++ is a descendant of C, these functions are often still useful in C++ programs.
The C++ standard library is a collection of code defined by the ISO (International Standards Organization), that must be included with every standards-compliant compiler. Unfortunately, as of this writing, there are no completely standards-compliant compilers, but the one on the CD in the back of the book should be close enough for programs you will be writing. The types defined in the standard library include the vector and string classes that we have used either directly or indirectly throughout this book, as well as hundreds of other very useful types and functions.
A C string is a sequence of characters referred to by a char* pointer. Do not confuse this with the C++ string class.
A C string literal is a literal value representing a variable number of characters. An example is "This is a test.". C string literals are surrounded by double quotes ("). The name of this data type indicates its origin in C, which did not have a real string type such as the C++ string. While these two types have some similarities, they behave quite differently and should not be confused with one another.
A call instruction is an assembly language instruction used to implement a function call. It saves the program counter on the stack and then transfers execution from the calling function to the called function.
A called function is a function that starts execution as the result of a function call. Normally, it returns to the calling function via a return statement when finished.
A calling function is a function that suspends execution as a result of a function call; the called function begins execution at the point of the function call.
The carriage return character is used to signal the end of a line of text. Also see newline in the index.
A function is said to be case-sensitive if upper- and lower-case letters are considered to be distinct.
A function is said to be case-insensitive if upper- and lower-case letters are considered equivalent. See less_nocase in the index.
To catch an exception means to handle an interruption in the normal flow control of a program, usually due to an error condition. An exception is generated via a throw statement, and can be caught in a function that has directly or indirectly called the function that threw the exception. The catch keyword is used in conjunction with try, which specifies a block of code to which a specific catch statement or statements may be applicable. A catch can specify the type of exceptions that it will handle, or can use "..." to specify that it will handle any and all exceptions.
A char is an integer variable type that can represent either one character of text or a small whole number. Both signed and unsigned chars are available for use as "really short" integer variables; a signed char can represent a number from -128 to +127, whereas an unsigned char can represent a number from 0 to 255. (In case you were wondering, the most common pronunciation of char has an "a" as in "married", while the "ch" sounds like "k". Other pronunciations include the standard English pronunciation of "char" as in overcooking meat, and even "car" as in "automobile".)2
A char* (pronounced "char star") is a pointer to (i.e., the memory address of) a char or the first of a group of chars.
A class implementation tells the compiler how to implement the facilities defined in the class interface. It is usually found in an implementation file, which the compiler on the CD in the back of this book assumes has the extension .cpp.
A class interface tells the user of the class what facilities the class provides by specifying the class's public member functions. The class interface also tells the compiler what data elements are included in objects of the class, but this is not logically part of the interface. A class interface is usually found in a header file - that is, one with the extension .h.
The class membership operator, ::, indicates which class a function belongs to. For example, the full name of the default constructor for the string class is string::string().
class scope describes the visibility of member variables - that is, those defined within a class. A variable with this scope can be accessed by any member function of its class; its accessibility to other functions is controlled by the access specifier in effect when it was defined in the class interface.
A comment is a note to yourself or another programmer; it is ignored by the compiler. The symbol // marks the beginning of a comment; the comment continues until the end of the line containing the //. For those of you with BASIC experience, this is just like REM (the "remark" keyword) - anything after it on a line is ignored by the compiler.
Compilation is the process of translating source code into an object program, which is composed of machine instructions along with the data needed by those instructions. Virtually all software is created by this process.
A compiler-generated function is supplied by the compiler because the existence of that function is fundamental to the notion of a concrete data type. The compiler will automatically generate its own version of any of the following functions if they are not provided by the creator of the class: the assignment operator, the copy constructor, the default constructor, and the destructor.
A compiler warning is a message from the compiler informing the programmer of a potentially erroneous construct. While a warning does not prevent the compiler from generating an executable program, a wise programmer will heed such warnings, as they often reveal hazardous coding practices.
Concatenation is the operation of appending a string to the end of another string. Also see operator + in the index.
A concrete data type is a class whose objects behave like variables of native data types. That is, the class gives the compiler enough information that objects of that class can be created, copied, assigned, and automatically destroyed at the end of their useful lifetimes, just as native variables are.
The keyword const has two distinct meanings as employed in this book. The first is as a modifier to an argument of a function. In this context, it means that we are promising not to modify the value of that argument in the function. An example of this use might be the function declaration string& operator = (const string& Str);. The second use of const in this book is to define a data item similar to a variable, except that its value cannot be changed once it has been initialized. For this reason, it is mandatory to supply an initial value when creating a const. An example of this use is const short x = 5;.
A constructor is a member function that creates new objects of a (particular) class type. All constructors have the same name as that of the class for which they are constructors; for example, the constructors for the string class have the name string. A constructor that takes only one required argument is also a conversion function.
A continuation expression is the part of a for statement computed before every execution of the controlled block. The block controlled by the for will be executed if the result of the computation is true but not if it is false. See for statement for an example.
The continue keyword causes execution of a for loop to continue to the next iteration without executing any further statements in the current iteration.
A controlled block is a block under the control of a loop control statement or an if or else statement. The controlled block of a loop control statement can be executed a variable number of times, whereas the controlled block of an if or else statement is executed either once or not at all.
A conversion function is a member function that converts an object of its class to some other type, or vice versa. Also see implicit conversion.
A copy constructor makes a new object with the same contents as an existing object of the same type.
cout (pronounced "see out") is a predefined ostream; characters sent to it are displayed on the screen.
CPU is an abbreviation for Central Processing Unit. This is the "active" part of your computer, which executes all the machine instructions that make the computer do useful work.
The curly braces { and } are used to surround a block. The compiler treats the statements in the block as one statement.
A cursor is an abstract object that represents the position on the screen where input or output will occur next.
D
Data refers to the pieces of information that are operated on by programs. Originally, "data" was the plural of "datum"; however, the form "data" is now commonly used as both singular and plural.
A debugger is a program that controls the execution of another program so that you can see what the latter program is doing. You can download a debugger from the WWW that is compatible with the development environment on the CD in the back of this book.
Debugging is the art of finding and eradicating errors (bugs) from your program. One of the best ways of debugging a program is to try to explain it to someone else in great detail. If you don't see your error, the other person almost certainly will!
A dedicated register is a register such as the stack pointer whose usage is predefined rather than determined by the programmer, as in the case of general registers such as eax.
A default argument is a method of specifying a value for an argument to a function when the user of the function doesn't supply a value for that argument. The value of the default argument is specified in the declaration of the function.
A default constructor is a member function that is used to create an object when no initial value is specified for that object. For example, string::string() is the default constructor for the string class.
The default keyword is used with the switch statement to specify an action to be performed when none of the case statements match the selection expression of the switch.
The delete operator is used to free memory previously used for variables of the dynamic storage class. This allows the memory to be reused for other variables.
A destructor is a member function that cleans up when an object expires; for an object of the auto storage class, the destructor is called automatically at the end of the block where that object is defined.
A digit is one of the characters used in any positional numbering system to represent all numbers starting at 0 and ending at one less than the base of the numbering system. In the decimal system, there are ten digits, `0' through `9', and in the hexadecimal system, there are sixteen digits, `0' through 9 and `a' through `f'.
A double is a type of floating-point variable that can represent a range of positive and negative numbers, including fractional values. With most current C++ compilers, including the one on the CD in the back of the book, these numbers can vary from approximately 4.940656e - 324 to approximately 1.79769e + 308 (and 0), with approximately 16 digits of precision.
Dynamic memory allocation is the practice of assigning memory locations to variables during execution of the program by explicit request of the programmer.
Variables of the dynamic storage class are assigned memory addresses at the programmer's explicit request. This storage class is often used for variables whose size is not known until run time.
Dynamic type checking refers to checking the correct usage of variables of different types during execution of a program rather than during compilation; see type system for further discussion.
Dynamic typing means delaying the determination of the exact type of a variable until run time rather than fixing that type at compile time, as in static typing. Please note that dynamic typing is not the same as dynamic type checking; C++ has the former but not the latter. See type system for further discussion.
E
The keyword else causes its controlled block to be executed if the condition in its matching if statement turns out to be false at run time.
Encapsulation means hiding the details of a class inside the implementation of that class rather than exposing them in the interface. This is one of the primary organizing principles of object-oriented programming.
An end user is the person who actually uses an application program to perform some useful or interesting task. Also see application programmer, library designer.
The Enter key is the key that generates a newline character, which tells an input routine that the user has finished entering data.
An enum is a way to define a number of unchangeable values, which are quite similar to consts. The value of each successive name in an enum is automatically incremented from the value of the previous name (if you don't specify another value explicitly). The term enum is short for "enumeration", which is a list of named items.
An exception is an interruption in the normal flow of control in a program. When a function encounters an error condition, it can "throw an exception" to notify any calling function that wishes to handle this problem that it has occurred. If none of the calling functions handles the exception via a catch statement, the program will terminate.
An executable program is a program in a form suitable for running on a computer; it is composed of machine instructions along with data needed by those instructions.
The explicit keyword tells the compiler not to call a specified constructor unless that constructor has been called explicitly. This prevents such a constructor from being called to perform an implicit conversion.
F
The keyword false is a predefined value representing the result of a conditional expression whose condition is not satisfied. For example, in the conditional expression x < y, if x is not less than y, the result of the expression will be false. Also see bool.
A fencepost error is a logical error that causes a loop to be executed one more or one fewer time than the correct count. A common cause of this error is confusing the number of elements in a vector or array with the index of the last element. The derivation of this term is by analogy with the problem of calculating the number of fence sections and fenceposts that you need for a given fence. For example, if you have to put up a fence 100 feet long and each section of the fence is 10 feet long, how many sections of fence do you need? Obviously, the answer is 10. Now, how many fenceposts do you need? 11. The confusion caused by counting fenceposts when you should be counting segments of fence (and vice versa) is the cause of a fencepost error. To return to a programming example, if you have a vector with 11 elements, the index of the last element is 10, not 11. Confusing the number of elements with the highest index has much the same effect as that of the fencepost problem. This sort of problem is also known, less colorfully, as an off-by-one error.
A float is a type of floating-point variable that can represent a range of positive and negative numbers, including fractional values. With most current C++ compilers, including the one on the CD in the back of the book, these numbers can vary from approximately 1.401298e - 45 to approximately 3.40282e + 38 (and 0), with approximately 6 digits of precision.
A floating-point variable is a C++ approximation of a mathematical "real number". Unlike mathematical real numbers, C++ floating-point variables have a limited range and precision depending on their types. See the individual types float and double for details.
A for statement is a loop control statement that causes its controlled block to be executed while a specified logical expression (the continuation expression) is true. It also provides for a starting expression to be executed before the first execution of the controlled block and for a modification expression to be executed after every execution of the controlled block. For example, in the for statement for (i = 0; i < 10; i ++), the initialization expression is i = 0, the continuation expression is i < 10, and the modification expression is i ++.
The keyword friend allows access by a specified class or function to private or protected members of a particular class.
A function is a section of code having a name, optional arguments, and a return type. The name makes it possible for one function to start execution of another one via a function call. The arguments provide input for the function, and the return type allows the function to provide output to its calling function when the return statement causes the calling function to resume execution.
A function call (or call for short) causes execution to be transferred temporarily from the current function (the calling function) to the one named in the function call (the called function). Normally, when a called function is finished with its task, it returns to the calling function, which picks up execution at the statement after the function call.
A function declaration tells the compiler some vital statistics of the function: its name, its arguments, and its return type. Before we can use a function, the compiler must have already seen its function declaration. The most common way to arrange for this is to use a #include statement to insert the function declaration from a header file into an implementation file.
Function overloading is the C++ facility that allows us to create more than one function with the same name. So long as all such functions have different signatures, we can write as many of them as we wish and the compiler will be able to figure out which one we mean.
G
A general register is a register whose usage is determined by the programmer, not predefined as with dedicated registers such as the stack pointer. On an Intel CPU such as the 486 or Pentium, the 16-bit general registers are ax, bx, cx, dx, si, di, and bp; the 32-bit general registers are eax, ebx, ecx, edx, esi, edi, and ebp.
A get pointer holds the address of the next byte in the input area of an istream - that is, where the next byte will be retrieved if we use >> to read data from the stream.
Global scope describes the visibility of variables defined outside any function; such variables can be accessed by code in any function. It also describes the visibility of functions defined outside any class.
The global namespace is a name for the set of identifiers visible to all functions without a class or namespace name being specified. Adding identifiers to the global namespace should be avoided when possible, as such identifiers can conflict with other similar identifiers defined by other programmers.
H
Hardware refers to the physical components of a computer - the ones you can touch. Examples include the keyboard, the monitor, and the printer.
A header file is a file that contains class interface definitions and/or global function declarations. By convention, header files have the extension .h.
I
An identifier is a user-defined name; both function names and variable names are identifiers. Identifiers must not conflict with keywords such as if and for; for example, you cannot create a function or a variable with the name for.
An if statement is a statement that causes its controlled block to be executed if the logical expression specified in the if statement is true.
An implementation file contains source code statements that are turned into executable code by a compiler. In this book, implementation files have the extension .cpp.
An implicit conversion is one that occurs without the programmer's explicit request. Also see explicit.
An include guard is a mechanism used to prevent the same class definition from being included in the same source code file more than once.
To increment a variable means to add 1 to its value. This can be done in C++ by using the increment operator, ++.
An index is an expression used to select one of a number of elements of a vector or an array. It is enclosed in square brackets ([ ]). For example, in the expression a[i+1], the index is the expression i+1.
Inheritance is the definition of one class as a more specific version of another previously defined class. The newly defined class is called the derived (or sometimes the child) class, while the previously defined class is called the base (or sometimes the parent) class. In this book, we use the terms base and derived. The derived class inherits all of the member variables and regular member functions from the base class. Inheritance is one of the primary organizing principles of object-oriented programming.
Initialization is the process of setting the initial value of a variable or const. It is very similar to assignment but not identical. Initialization is done only when a variable or const is created, whereas a variable can be assigned to as many times as desired. A const, however, cannot be assigned to at all, so it must be initialized when it is created.
Input is the process of reading data into the computer from the outside world. A very commonly used source of input for simple programs is the keyboard.
An int (short for integer) is a type of integer variable. While the C++ language definition requires only that an int be at least as long as a short and no longer than a long, with most current C++ compilers this type is equivalent to either a short or a long, depending on the compiler you are using. A 16-bit compiler, such as Borland C++ 3.1, has 16-bit (2-byte) ints that are the same size as shorts. A 32-bit compiler, such as the one on the CD in the back of the book, has 32-bit (4-byte) ints that are the same size as longs.
An integer variable is a C++ representation of a whole number. Unlike mathematical integers, C++ integers have a limited range, which varies depending on their types. See the individual types char, short, int, and long for details. The type bool is sometimes also considered an integer variable type.
I/O is an abbreviation for "input/output". This refers to the process of getting information into and out of the computer. See input and output for more details.
iostream is the name of the header file that tells the compiler how to compile code that uses predefined stream variables like cout and cin and operators like << and >>.
An object of a derived class is said to have an "isA" relationship with its base class if the derived class object can properly be substituted for a base class object. In C++, objects of publicly derived classes should have this relationship with their base classes.
An istream is a stream used for input. For example, cin is a predefined istream that reads characters from the keyboard.
K
A keyword is a word defined in the C++ language, such as if and for. It is illegal to define an identifier such as a variable or function name that conflicts with a keyword; for example, you cannot create a function or a variable with the name for.
L
A library (or library module) contains the object code generated from several implementation files, in a form that the linker can search when it needs to find general-purpose functions.
A library designer is a programmer who creates classes for application programmers to use in writing application programs.
The linker is a program that combines information from all of the object files for our program, along with some previously prepared files called libraries, to produce an executable program.
A literal value is a value that doesn't have a name, but instead represents itself in a literal manner. Some examples are `x' (a char literal having the ASCII value that represents the letter "x") and 5 (a numeric literal with the value 5).
Local scope describes the visibility of variables defined within a function; such variables can be accessed only by code in that function.3
A logical expression is an expression that takes on the value true or false rather than a numeric value. Some examples of such an expression are x > y (which will be true if x has a greater value than y and false otherwise) and a == b (which will be true if a has the same value as b, and false otherwise). Also see bool.
A long is a type of integer variable that can represent a whole number. With most current C++ compilers, including the one on the CD in the back of the book, a long occupies 4 bytes of storage and therefore can represent a number in either the range -2147483648 to 2147483647 (if signed) or the range 0 to 4294967295 (if unsigned).
A loop is a means of executing a controlled block a variable number of times depending on some condition. The statement that controls the controlled block is called a loop control statement. This book covers the while and for loop control statements. See while and for for details.
M
Machine code is the combination of machine instructions and the data they use. A synonym is object code.
A machine instruction is one of the fundamental operations that a CPU can perform. Some examples of these operations are addition, subtraction, or other arithmetic operations; other possibilities include operations that control what instruction will be executed next. All C++ programs must be converted into machine instructions before they can be executed by the CPU.
A magic number is a number that does not have any obvious relationship to the rest of the code. A good general rule is that numbers other than 0, 1, or other self-evident values should be defined as const or enum values rather than as literal values such as `7'.
The manager/worker idiom (also known as the "envelope/letter idiom") is a mechanism that allows the effective type of an object to be determined at run time without requiring the user of the object to be concerned with pointers. It is used to implement polymorphic objects in C++.
A manipulator is a member function of one of the iostream classes that controls how output will be formatted without necessarily producing any output of its own. Manipulators operate on fields; a field can be defined as the result of one << operator.
A member function is a function defined in a class interface. It is viewed as "belonging" to the class, which is the reason for the adjective "member".
A member initialization expression is the preferred method of specifying how a member variable is to be initialized in a constructor. Also see inheritance.
A member initialization list specifies how member variables are to be initialized in a constructor. It includes two types of expressions: base class initializers and member initialization expressions. Also see inheritance.
A member variable is a variable defined in a class interface. It is viewed as "belonging" to the class, which is the reason for the adjective "member".
Memberwise copy means to copy every member variable from the source object to the destination object. If we don't define our own copy constructor or assignment operator for a particular class, the compiler-generated versions will use memberwise copy.
A memory hierarchy is the particular arrangement of the different kinds of storage devices in a given computer. The purpose of using storage devices having different performance characteristics is to provide the best overall performance at the lowest cost.
A memory leak is a programming error in which the programmer forgot to delete something that had been dynamically allocated. Such an error is very insidious because the program appears to work correctly when tested casually. When such errors exist in a program, they are usually found only after the program runs apparently correctly for a (possibly long) time and then fails because it runs out of available memory.
A modification expression is the part of a for statement executed after every execution of the controlled block. It is often used to increment an index variable to refer to the next element of an array or vector; see for statement for an example.
N
A native data type is one defined in the C++ language, as opposed to a user-defined data type (class).
The new operator is used to allocate memory for variables of the dynamic storage class; these are usually variables whose storage requirements aren't known until the program is executing.
A nonmember function is one that is not a member of a particular class being discussed, although it may be a member function of another class.
A nonnumeric variable is a variable that is not used in calculations like adding, multiplying, or subtracting. Such variables might represent names, addresses, telephone numbers, Social Security numbers, bank account numbers, or driver's license numbers. Note that even a data item referred to as a number and composed entirely of the digits 0 through 9 may be a nonnumeric variable by this definition; the question is how the item is used. No one adds, multiplies, or subtracts driver's license numbers, for example; these numbers serve solely as identifiers and could just as easily have letters in them, as indeed some of them do.
A nonprinting character is used to control the format of our displayed or printed information, rather than to represent a particular letter, digit, or other special character. The space is one of the more important nonprinting characters.
A non-virtual function is one that is not declared with the virtual keyword either in the class in question or any base class of that class. This means that the compiler can decide at compile time the exact version of the function to be executed when it is referred to via a base class pointer or base class reference.
A normal constructor is a constructor whose arguments supply enough information to initialize all of the member fields in the object being created.
A null byte is a byte with the value 0, commonly used to indicate the end of a C string. Note that this is not the same as the character "0", which is a normal printable character having the ASCII code 48.
A null object is an object of some (specified) class whose purpose is to indicate that a "real" object of that class does not exist. It is analogous to a null pointer. One common use for a null object is as a return value from a member function that is supposed to return an object with some specified properties but cannot find such an object. For example, a null StockItem object might be used to indicate that an item with a specified UPC cannot be found in the inventory of a store.
A null pointer is a pointer with the value 0. This value is particularly suited to indicate that a pointer isn't pointing to anything at the moment, because of some special treatment of zero-valued pointers built into the C++ language.
A numeric variable is a variable that represents a quantity that can be expressed as a number, whether a whole number (an integer variable) or a number with a fractional part (a floating-point variable), and that can be used in calculations such as addition, subtraction, multiplication, or division. The integer variable types in C++ are char, short, int, and long. Each of these can be further subdivided into signed and unsigned versions. The signed versions can represent both negative and positive values (and 0), whereas the unsigned versions can represent only positive values (and 0) but provide greater ranges of positive values than the corresponding signed versions do. The floating-point variable types are float and double, which differ in their range and precision. Unlike the integer variable types, the floating-point types are not divided into signed and unsigned versions; all floating-point variables can represent either positive or negative numbers as well as 0. See float and double for details on range and precision.
O
An object is a variable of a class type, as distinct from a variable of a native type. The behavior of an object is defined by the code that implements the class to which the object belongs. For example, a variable of type string is an object whose behavior is controlled by the definition of the string class.
An object code module is the result of compiling an implementation file into object code. A number of object code modules are combined to form an executable program. This term is unrelated to C++ objects.
Object-oriented programming, in a broad sense, is an approach to solving programming problems by creating objects to represent the entities being handled by the program, rather than by relying solely on native data types. This has the advantage that you can match the language to the needs of the problem you're trying to solve. For example, if you were writing a nurse's station program in C++, you would have objects that represent nurses, doctors, patients, various sorts of equipment, and so on. Each of these objects would display the behavior appropriate to the thing or person it represents.
In a more specific sense, object-oriented programming is the use of encapsulation, inheritance, and polymorphism to organize programs.
An op code is the part of a machine instruction that tells the CPU what kind of instruction it is and sometimes also specifies a register to be operated on.
An operating system is a program that deals with the actual hardware of your computer. It supplies the lowest level of the software infrastructure needed to run a program. The most common operating system for Intel CPUs, at present, is some form of Windows, followed by Linux.
The keyword operator is used to indicate that the following symbol is the name of a C++ operator we are overloading to handle the particular requirements of a specific class. For example, to define our own version of =, we have to specify operator = as the name of the function we are writing, rather than just =, so that the compiler does not object to seeing an operator when it expects an identifier.
An ostream is a stream used for output. For example, cout is a predefined ostream that displays characters on the screen.
Output is the process of sending data from the computer to the outside world. The most commonly used destination of output for most programs is the screen.
A member function in a derived class is said to override the base class member function if the derived class function has the same signature (name and argument types) as that of the base class member function. The derived class member function will be called instead of the base class member function when the member function is referred to via an object of the derived class. A member function in a derived class with the same name but a different signature from that of a member function in the base class does not override the base class member function. Instead, it "hides" that base class member function, which is no longer accessible as a member function in the derived class.
Overloading a function means to create several functions with the same name and different argument lists. The compiler will pick the function to be executed based on the match between the function call and the available argument lists.
P
A pointer is essentially the same as a memory address. The main difference is that a memory address is "untyped" (i.e., it can refer to any sort of variable) whereas a pointer always has an associated data type. For example, char* (pronounced "char star") means "pointer to a char". To say "a variable points to a memory location" is almost the same as saying "a variable's value is the address of a memory location". In the specific case of a variable of type char*, to say "the char* x points to a C string" is essentially equivalent to saying "x contains the address of the first byte of the C string". Also see array.
A polymorphic object is a C++ object that behaves polymorphically without exposing the user of the object to the hazards of pointers. The user does not have to know any of the details of the implementation, but merely instantiates an object of the single visible class (the manager class). That object does what the user wants with the help of an object of a worker class, which is derived from the manager class. Also see manager/worker idiom.
Polymorphism is the major organizing principle in C++ that allows us to implement several classes with the same interface and to treat objects of all these classes as though they were of the same class. Polymorphism is a variety of dynamic typing that maintains the safety factor of static type checking, because the compiler can determine at compile time whether a function call is legal even if it does not know the exact type of the object that will receive that function call at run time. "Polymorphism" is derived from the Greek poly, meaning "many", and morph, meaning "form". In other words, the same behavior is implemented in different forms.
The preprocessor is a part of the C++ compiler that deals with the source code of a program before the rest of the compiler ever sees that source code.
A preprocessor directive is a command telling the preprocessor to handle the following source code in a special manner.
A preprocessor symbol is a constant value similar to a const, but it is known only to the preprocessor, not to the rest of the compiler. The rules for naming preprocessor symbols are the same as those for other identifiers, but it is customary to use all upper-case letters in preprocessor symbols so that they can be readily distinguished from other identifiers.
The keyword private is an access specifier that denies nonmember functions access to member functions and member variables of its class.
Creating a class via private inheritance means that we are not going to allow outside functions to treat an object of the derived class as an object of the base class. That is, functions that take a base class object as a parameter will not accept a derived class object in its place. None of the public member functions and public data items (if there are any) in the base class will be accessible to the outside world via a privately derived class object. Contrast with public inheritance.
A program is a set of instructions specifying the solution to a set of problems, along with the data used by those instructions.
The program counter is a dedicated register that holds the address of the next instruction to be executed. During a function call, a call instruction pushes the contents of the program counter on the stack. This enables the called function to return to the calling function when finished.
Program failure can be defined as a situation in which a program does not behave as intended. The causes of this are legion, ranging from incorrect input data to improper specification of the problem to be solved.
Program maintenance is the process of updating and correcting a program once it has entered service.
- 1. Find or invent a general solution to a set of problems.
- 2. Express this solution as an algorithm or set of algorithms.
- 3. Translate the algorithm(s) into terms so simple that a stupid machine like a computer can follow them to calculate the specific answer for any specific problem in the set.
Warning: This definition may be somewhat misleading, since it implies that the development of a program is straightforward and linear, with no revision. This is known as the "waterfall model" of programming, since water going over a waterfall follows a preordained course in one direction. However, real-life programming doesn't usually work this way; rather, most programs are written in an incremental process as assumptions are changed and errors are found and corrected.
The keyword protected is an access specifier. When present in a base class definition, it allows derived class functions access to member variables and functions in the base class part of a derived class object, while preventing access by other functions outside the base class.
The keyword public is an access specifier that allows nonmember functions access to member functions and member variables of its class.
Creating a class via public inheritance means that we are going to let outside functions treat an object of the derived class as an object of the base class. That is, any function that takes a base class object as a parameter will accept a derived class object in its place. All of the public member functions and public data items (if there are any) in the base class are accessible to the outside world via a derived class object as well. Contrast with private inheritance.
A put pointer holds the address of the next byte in the output area of an ostream - that is, where the next byte will be stored if we use << to write data into the stream.
R
RAM is an acronym for Random Access Memory. This is the working storage of a computer, where data and programs are stored while we're using them.
A reference is an identifier that acts as another name for an existing variable rather than as an independent variable. Changing a reference therefore affects the corresponding variable. In this book, we use references only for passing arguments to functions.
A reference argument is another name for a variable from a calling function rather than an independent variable in the called function. Changing a reference argument therefore affects the corresponding variable in the calling function. Compare with value argument.
The reference-counting idiom is a mechanism that allows one object (the "reference-counted object") to be shared by several other objects (the "client objects") rather than requiring a separate copy for each of the client objects.
A register is a storage area that is on the same chip as the CPU itself. Programs use registers to hold data items that are actively in use; data in registers can be accessed within the time allocated to instruction execution rather than the much longer times needed to access data in RAM.
Regression testing means running a modified program and verifying whether previously working functionality is still working.
- 1. constructor,
- 2. destructor,
- 3. the assignment operator, operator =.
A retrieval function is a function that retrieves data that may have been previously stored by a storage function or that may be generated when needed by some other method such as calculation according to a formula.
A return address is the memory address of the next machine instruction in a calling function. It is used during execution of a return statement in a called function to transfer execution back to the correct place in the calling function.
A return statement is used by a called function to transfer execution back to the calling function. The return statement can also specify a value of the correct return type for the called function. This value is made available to the calling function to be used for further calculation. An example of a return statement is return 0;, which returns the value 0 to the calling function.
A return type tells the compiler what sort of data a called function returns to the calling function when the called function finishes executing. The return value from main is a special case; it can be used to determine what action a batch file should take next.
ROM is an abbreviation for Read-Only Memory. This is the permanent internal storage of a computer, where the programs needed to start up the computer are stored. As this suggests, ROM does not lose its contents when the power is turned off, as contrasted with RAM.
The run-time type of a variable is the type that variable has when the program is being executed. In the presence of polymorphism, this type may differ from the type with which the variable was declared at compile time.
S
A scalar variable has a single value (at any one time); this is contrasted with a vector or an array, which contains a number of values, each of which is referred to by its index.
The scope of a variable is the part of the program in which the variable can be accessed. The scopes with which we are concerned are local, global, and class; see local scope, global scope, and class scope for more details.
A selection expression is the part of a switch statement that specifies an expression used to select an alternative section of code.
A selection sort is a sorting algorithm that selects the highest (or lowest) element from a set of elements (the "input list") and moves that selected element to another set of elements (the "output list"); the next highest (or lowest) element is then treated in the same manner. This operation is repeated until as many elements as desired have been moved to the output list.
A short is a type of integer variable that can represent a whole number. With most current C++ compilers, including the one on the CD in the back of the book, a short occupies 2 bytes of storage and therefore can represent a number in either the range -32768 to 32767 (if signed) or the range 0 to 65535 (if unsigned).
The short-circuit evaluation rule governs the execution of the || and && operators. See || and && for details.
A side effect is any result of calling a function that persists beyond the execution of that function other than its returning a return value. For example, writing data to a file is a side effect.
The signature of a function consists of its name and the types of its arguments. In the case of a member function, the class to which the function belongs is also part of its signature. Every function is uniquely identified by its signature, which is what makes it possible to have more than one function with the same name. This is called function overloading.
A signed variable can represent either negative or positive values. See char, short, int, or long for details.
Slicing is the partial assignment that occurs when a derived class object is assigned to a base class variable. This term is used because in such an assignment only the base class part of the derived class object is assigned while the other fields are "sliced off".
Software refers to the nonphysical components of a computer, the ones you cannot touch. If you can install it on your hard disk, it's software. Examples include a spreadsheet, a word processor, and a database program.
The space character is one of the nonprinting characters (or nondisplay characters) that control the format of displayed or printed information.
Special constructor; a constructor used in the implementation of a polymorphic object to prevent an infinite recursion during construction of that object.
The square brackets, [ and ], are used to enclose an array or vector index, which selects an individual element of the array or vector. Also see [ ].
A stack is a data structure with characteristics similar to those of a spring-loaded plate holder such as you might see in a cafeteria. The last plate deposited on the stack of plates will be the first one removed when a customer needs a fresh plate; similarly, the last value deposited (pushed) onto a stack is the first value retrieved (popped).
The stack pointer is a dedicated register. It is used to keep track of the address of the most recently pushed value on the stack.
A starting expression is the part of a for statement that is executed once before the controlled block of the for statement is first executed. It is often used to initialize an index variable to 0 so that the index variable can be used to refer to the first element of an array or vector. See for statement for an example.
A statement is a complete operation understood by the C++ compiler. Each statement ends with a semicolon (;).
A static member function is a member function of a class that can be called without reference to an object of that class. Such a function has no this pointer passed to it on entry and therefore cannot refer to normal (non-static) member variables of the class.
A static member variable is a member variable of a class that is shared among all objects of that class. This is distinct from the treatment of the normal (non-static) member variables of the class. Each object of a class has its own set of normal member variables.
The static storage class is the simplest of the three storage classes in C++; variables of this storage class are assigned memory addresses in the executable program when the program is linked. This use of the term "static" is distinct from but related to the keyword static.
Static type checking refers to the practice of checking the correct usage of variables of different types during compilation of a program rather than during execution. C++ uses static type checking. See type system for further discussion. Note that this has no particular relation to the keyword static.
Static typing means determining the exact type of a variable when the program is compiled. It is the default typing mechanism in C++. Note that this has no particular relation to the keyword static, nor is it exactly the same as static type checking. See type system for further discussion.
std:: is the name of the standard C++ library namespace. This namespace contains the names of all of the functions and variables declared in the standard library.
Stepwise refinement is the process of developing an algorithm by starting out with a "coarse" solution and "refining" it until the steps are within the capability of the programming language you are using to write a program.
A storage class is the characteristic of a variable that determines how and when a memory address is assigned to that variable. C++ has three storage classes: static, auto, and dynamic. Please note that the term storage class has nothing to do with the C++ term class. See static storage class, auto storage class, and dynamic storage class for more details.
A stream is a place to put (in the case of an ostream) or get (in the case of an istream) characters. Two predefined streams are cin and cout.
The string class defines a type of object that contains a group of chars; the chars in a string can be treated as one unit for purposes of assignment, I/O, and comparison.
A stringstream is a type of stream that exists only in memory rather than being attached to an input or output device. It is often used for formatting of data that is to be further manipulated within the program.
The switch statement is effectively equivalent to a number of if/else statements in a row, but is easier to read and modify. The keyword switch is followed by a selection expression (in parentheses), which specifies an expression that is used to select an alternative section of code. The various alternatives to be considered are enclosed in a set of curly braces following the selection expression. Each alternative is marked off by the keyword case followed by the (constant) value to be matched and a colon.
T
A temporary variable is automatically created by the compiler for use during a particular operation, such as a function call with an argument that has to be converted to a different type.
The keyword this represents a hidden argument automatically supplied by the compiler in every (non-static) member function call. Its value during the execution of any member function is the address of the class object for which the member function call was made.
To throw an exception means to cause an interruption in the normal flow control of a program, usually due to an error condition. An exception can be handled via a catch statement in a function that directly or indirectly called the function that threw the exception.
A token is a part of a program that the compiler treats as a separate unit. It's analogous to a word in English, while a statement is more like a sentence. For example, string is a token, as are :: and (, whereas x = 5; is a statement.
The keyword true is a predefined value representing the result of a conditional expression whose condition is satisfied. For example, in the conditional expression x < y, if x is less than y, the result of the expression will be true.
The keyword try is used to control a block from which an exception may be generated. If an exception occurs during execution of that block or any functions within that block, the following catch statement will be invited to handle the exception, assuming that the specification of the catch statement indicates that it is willing to handle such an exception.
The type of an object is the class to which it belongs. The type of a native variable is one of the predefined variable types in C++. See integer variable, floating-point variable, and bool for details on the native types.
The type system refers to the set of rules the language uses to decide how a variable of a given type may be employed. In C++, these determinations are made by the compiler (static type checking). This makes it easier to prevent type errors than it is in languages where type checking is done during execution of the program (dynamic type checking). Please note that C++ has both static type checking and dynamic typing. This is possible because the set of types that is acceptable in any given situation can be determined at compile time, even though the exact type of a given variable may not be known until run time.
U
An uninitialized variable is one that has never been set to a known value. Attempting to use such a variable is a logical error that can cause a program to act very oddly.
An unqualified name is a reference to a member variable that doesn't specify which object the member variable belongs to. When we use an unqualified name in a member function, the compiler assumes that the object we are referring to is the object for which that member function has been called.
An unsigned variable is an integer variable that represents only positive values (and 0). See char, short, int, and long for details.
The term user has several meanings in programming. The primary usage in this book is application programmer; however, it can also mean library designer (in the phrase user-defined data type) or even end user.
A user-defined data type is one that is defined by the user. In this context, user means "someone using language facilities to extend the range of variable types in the language", or library designer. The primary mechanism for defining a user-defined type is the class.
A using declaration tells the compiler to import one or more names from a particular namespace into the current namespace. This allows the use of such names without having to explicitly specify the namespace from which they come.
V
A value argument is a variable of local scope created when a function begins execution. Its initial value is set to the value of the corresponding argument in the calling function. Changing a value argument does not affect any variable in the calling function. Compare with reference argument.
A variable is a programming construct that uses a certain part of RAM to represent a specific item of data we wish to keep track of in a program. Some examples are the weight of a pumpkin or the number of cartons of milk in the inventory of a store.
A vector is a group of variables, each of which can be addressed by its position in the group; each of these variables is called an element. A vector has a name, just as a regular variable does, but the elements do not. Instead, each element has an index that represents its position in the vector.
A Vec is exactly like a vector except that it checks the validity of the index of an element before allowing access to that element.
Declaring a function to be virtual means that it is a member of a set of functions having the same signatures and belonging to classes related by inheritance. The actual function to be executed as the result of a given function call is selected from this set of functions dynamically (i.e., at run time) based on the actual type of an object referred to via a base class pointer (or base class reference). This is the C++ dynamic typing mechanism used to implement polymorphism, in contrast to the static typing used for non-virtual functions, where the exact function to be called can be determined at compile time.
A void return type specifier in a function declaration indicates that the function in question does not return any value when it finishes executing.
The term vtable is an abbreviation for virtual function address table. It is where the addresses of all of the virtual functions for a given class are stored; every object of that class contains the address of the vtable for that class.5
W
A while statement is a loop control statement that causes its controlled block to be executed while a specified logical expression is true.
Y
Z
Zero-based indexing refers to the practice of numbering the elements of an array or vector starting at 0 rather than 1.
1As is often the case in C++, this operator (and the corresponding stream input operator, >>) have other almost completely unrelated meanings besides the ones defined here. I'm only bringing this up so that you won't be too surprised if and when you run into these other meanings in another textbook.
2Actually, a char can be larger than 8 bits. However, it is required by the C++ standard to be at least 8 bits, and the most common compilers and machines indeed do have 8-bit chars.
3In fact, a variable can be declared in any block, not just in a function. In that case, its scope is from the point where it is declared until the end of the block where it is defined.
5Note that the compiler is not required by the standard to use a vtable to implement virtual functions. However, that is the typical way of implementing such functions.
|
www.steveheller.com steve@steveheller.com |