|
ABOUT: C++ GLOSSARY LEGEND[This document was originally created in Microsoft Word from a compendium of resources. A Bibliography of these source materials appears at the bottom of this document. This is a study note effort and is not guaranteed to be authoritative. The source material in the glossary is coprighted by its authors. The glossary draws on that material and must not be sold or otherwise represented as original. By the same token, then, it is not public domain. It should be used as a recommended reading list, and as "pointers" to the original reference material only. This glossary is intended for use by students of C++, and presumes some knowledge of C. Most concepts are also useful for C. The original MSWD doc was cross-referenced by styled text. We've adapted this to HTML.]
access functions - those (public) functions within a class definition whose sole purpose is to provide access to the private data. Only member functions and friend functions may change values of private variables. access specifiers - public, private or protected. "alias" - defining an alias for a structure or built-in type allows use of the alias as if it were a new type. In C, the keyword is typedef. It's a bad idea to alias (have two objects pointing to the same data) unless one of those objects is a temporary variable. (From CIO p.483). allocating storage - "don't unless you must." (USG): "Instead of defining a Clone operator, overload the assignment operator; instead of allocating and returning an object, have the caller pass one in by reference and set it. This allows your classes to be treated just like primitive types ... leave storage allocation up to the class client. Design your classes so that using them is just like using primitive types in C. In cases where you wish to avoid copying, pass arguments by reference ...Exception: anytime a function must choose what type of object to return, the function must allocate the object, not the caller. arguments, function - Arguments in function declarations may have names, but the names are ignored (they are positional). In C++ (unlike C), an empty argument list means a function with no arguments, since the C "wild card" style would prevent type-checking, e.g., int func2(); this behavior is different than the result you would have expected in C. assignment operator: = *= /= %= += -= <<= >>= &= ^= != "All require an lvalue as left operand, and the lvalue must be modifiable: it must not be an array, and must not have an incomplete type, or be a function." (K&R p.208). At least the = operator is overloadable. automatic type conversion - e.g., casting a short to a void pointer (cannot do the reverse in C++). base object - a class or struct from which other classes defined as derived may inherit data members and member functions, subject to how both base and derived members are marked by access specifiers. "black box" - a model of a C function, or Pascal procedure, in which the details of the pieces are regarded as hidden, consisting of entities which produce a defined output for a given input, and in which model the "main" program consists of a collection of function calls. The ideal black box doesn't make changes to data outside its boundaries; practical black boxes must, through a side-effect process referred to as coupling. (from CIO, p.5). C libraries in C++ - To tell the C++ compiler to compile a C library, using C names, use an alternate language specification. Header files for C which have been prepared for C++ already contain these specifications. Example for a file called myheader.h:
casting - forced conversion of one data type to another by the = assignment operator, e.g., {short x; long y; y=x} character constant - single byte char enclosed by single quotes. class - An abstract data type. A keyword which defaults a struct class to private. A class binds into one unit the data structure and its functions, also called a user-defined type. Variables, or instances of that class, are called objects. const Qualifier - defines unchangeable initial object value. C++ prefers const to #define; enforces type-checking across multiple platforms and compilers and in other situations where type definitions have changed in your own program or the environment. (see USG). You can also use enums.
constructor function - C++ initialization for newly created object. Never returns a value. Unnecessary when no initialization needed. constructor parameters - typically used to provide initial values for a struct or class object's data members. Can be used to map param values from empty derived constructors to base class constructors. current object - the last-called or last-created object. data abstraction - C++ support for multiple entities and libraries; combination of the data structure and the operations on that data structure into a new abstract data type. Abstract data types behave just like built-in data types, but are created by the programmer. data hiding - Removing data from public view, e.g., making public members of the base class private in the derived class to disallow user access to certain base class functions. By controlling access, rather than building in error traps, we make the error compile-time rather than run-time. (CIO 24, 391). declaration - specifies to the compiler the types of all the elements of an identifier; "this function or this piece of data exists somewhere else, and here is what it should look like." Declarations normally go in header files with extensions of .h. See also definition for definition. default argument initializer - default value assigned to a called function's params, which is used when no param is provided by the function call. definition - instantiates an identifier, allocating its memory. A declaration can also be a definition. "Make this piece of data or this function here." Definitions normally go in implementation files with extensions of .cpp. See also declaration, function declaration, function definition. You can declare data or a function in many difference places, but can define it only once. delete - automatically calls the appropriate object destructor for you. derived class - declaration keyword specifying that a declared class has inheritance of all of the data members and member functions of the class from which it is declared to derive, e.g., class Derived : Base. Derived objects receive their own copies of called base object members. The compiler automatically calls constructors and destructors for called copies. destructor function - called by delete when a struct or class object is deleted or goes out of scope. Preceded by tilde (~); has no return value. Timing of delete or placement of call to destructor depends on scope of the object, i.e., global or local. dynamic memory allocation - In C and Pascal, a method to create space for variables at run time. For situations where you don't know at compile time how many objects you'll need, or what their lifetimes (scope) will be. encapsulation - combining of one or more like data members and fields into a single struct or class. C++ creates new data types for each struct, making it unnecessary to declare in struct declaration, and making it available for future struct defs. See also data abstraction. enumerations - declared enum with a list of enum constants; a vastly preferred alternative to preprocessor's #define to declare a series (a set) of constants, because it enforces type-checking across different compilers and platforms. (See USG; see const).
If you need to assign particular numerical values, you can do that too: enum ColorComponent {kRed = 0x10, kGreen = 0x20, kBlue = 0x40}; extern - keyword in C and C++ to help tell the compiler or user how to distinguish a definition from a declaration, when the definition is elsewhere, e.g.,
Since there is no function body { ...}, the compiler must treat the above as a function declaration rather than a function definition. The keyword is not needed to do this; it is optional. (CIO p.32) friend - keyword designating a class or single member function as having access to (1) a specified entire class, (2) a member function of another class, or (3) a designated nonmember function. If a friend declaration omits function's parameters, compiler checks for functions or overloaded functions with matching signatures, else reports error. According to USG, friends breach type safety and the integrity of class data abstraction; use them sparingly. function declaration - in C and C++, gives the function name, the argument types passed to a function, and the return type of the function; e.g.,
function definition - looks like function declarations, except with bodies, collections of statements inside curly braces, e.g.,
The arguments in the function definition must have names if you also want to use the arguments in the function body; otherwise, they are optional. function name overloading - C++ allows several functions sharing the same name but differing parameter lists ("signatures"); the candidate with the most closely matching signature is the one which gets called. This feature is useful to generate different versions of the same function, but they should all be related. (see USG). function call operator: () - an overloadable operator which always tells the compiler a function is being called. header file - contains the external declarations for a library, using a filename extension of .h . To use a library, you must include its header file. The programmer who provides the library provides the header file; to include it, use the #include preprocessor directive, and the compiler will insert it if the search is successful:
in C, a header file should not contain any function or data defs because the header can be included in more than one file, causing the linker to complain. In C++, there are two exceptions: inline, and const. See also: C libraries in C++ incomplete type - a specifier with a declaration (not definitions). implementation - consists of all class member function definitions, showing how a class's methods work. If an interface has already been compiled, only the implementation code need be compiled and linked at run time. (CIO p.108) inheritance - A C++ property which allows the defining of one class in terms of another. The compiler physically implements inheritance by making a copy of the data structure of the original base class into a declared derived class, and providing access to the member functions ion the base class. Inheritance allows you to add or modify members without corrupting the original class code. Conserves effort, and creates extensible programs through subclassing. See also polymorphism. (CIO, p.17,22). inline function - keyword forcing compiler to copy body of a called function into the calling function. Best for recursive and loop calls. Provides type safety and side-effects protection not afforded by #define. interface - C++ separates its interface from its implementation. The interface in C++ is the class definition of an object, and its methods. The interface doesn't specify how the methods work; this is done in the class implementation. Only the interface need be compiled at compile time. The implementation can be linked (or even written) at any time. You can compile a system to make sure it all fits together without writing its implementation. late binding - delayed resolving of a function; determination of the specific function of a subclass to be called, at run time. Late binding is an essential feature of C++; it implements C++'s polymorphism. lvalue - "An lvalue is an expression referring to an object ... an object is a named region of storage" (K&R p. 197). The left-hand side of the assignment operator (=) equation; what the rvalue is copied into. manipulators - special iostream functions permitting specific i/o operations while in the middle of stream insertion or extraction. These functions switch appropriate iostream format flags. member access operator: -> - When the compiler encounters the -> operator, it checks the type of the left-hand operand. If this is a pointer, -> is evaluated normally. If the operand is an object or object reference, it checks whether the object's call provides an -> overloading function. An overloadable operator, but, without an overload function, operator requires a pointer for the left-hand operand, not an object. See also: smart pointer. member function - a function within a struct body, having access to all the data members and member functions of the calling object. Must be preceded by class name and two colons (::), telling compiler this function is a member of the specified class.
multiple inheritance - a class derived from more than one class inherits the members from each of its base classes. Can introduce ambiguities; the derived class should be a union of each of the two base classes, not merely have some properties in common with each. This strongly implies each base class should have a common parent, the root base class. member initialization list - the list that follows the constructor's parameter list, as, from a derived constructor to base constructor(s). A colon always precedes the list. (LCM p.263). Constructor objects you define aren't used when you initialize one class object with the contents of another; instead, member-wise initialization is used to map the elements of the source object one at a time into the elements of the destination object. (CRS). member-wise initialization - special form of initialization used to copy the contents of one object, data member by data member, into another object. A convenient way of making a copy of another object, including any and all pointers. (LCM p. 279). One way of several:
caveat: if you delete one object, the other is left with a dangling pointer. messages - the actual function calls executed in an object-oriented language. See methods. methods - the functions that execute messages in an object-oriented language. object - a named region of storage (whether it has yet been allocated or not). See class. operator overload - compiler replacement of a C++ operator with a function called to overload it with a new meaning. Form: operator<c++ operator>; Example: float operator+(parm1, parm2){return (...)} would intercept and replace the plus (+) operator. Operator overloading means you can give an operator like + or - a special meaning when used with a new data type you create. (CIO , xxiii) operator overload, type matching - Parm types must agree [<type1> + <type1>], or additional "overloader overloading" handling will be needed [<type class> + <type float>]. (LCM p.173). Operators can only be overloaded by nonstatic class members functions. operator overload, special cases - new, delete, (), [], -> and = See: function call operator, subscript operator, member access operator, and assignment operator. operator overload, iostream - functions can be created to overload the >> or << iostream operators to provide custom data formatting and display. overload - see operator overload, function overload. One function name can be used in many different ways. Ordinary functions (not class methods) may be overloaded, providing a single function name and many argument lists. So may operators be overloaded; they may be assigned or reassigned to look like the syntax of other disciplines, such as math, stat., etc. Overloading is an aspect of the C++ idea of an "intelligent object" deciding what to do with a message. override,
member function - derived class member functions defined
to take precedence over base class member functions of the same
name, by declaring the base class member function with the keyword
virtual. pointer - see pointers vs. references below. pointers vs. references (USG) - a pointer must be dereferenced to access what it points to; a reference need not be. The entity to which a reference refers may only be set when the reference is created; in this respect it is somewhat like a const pointer that gets a virtual * put in front of it when it is used, and puts a virtual ampersand in front of the expression from which it is initialized.
References are mandatory in some cases, e.g., overloading the assignment operator. References should be used when the called function is "going to forget about" the argument once returned. A regular reference should be used if you are going to modify the argument (Tfoo &). A const reference should be used if you aren't, but don't want the overhead of a call by value (const Tfoo &). Pointers should be used when the called function is going to retain a reference (alias) to the object you are passing. Explicit use of pointers lets the reader know aliasing is occurring. (all from USG). polymorphism - lets you use objects of different classes by means of the same program element (CRS); use of identical interfaces with different implementations (CIO p.18). A program designed around polymorphism manages a collection of base-class objects, and the precise result of a message sent to one of these cannot be determined at compile time, since only the base class is known, not the subclass. Polymorphism is the proper behavior of a derived-class object when treated as a base-class object (without knowing exactly what type of object you're dealing with). (CIO p.23). The specific function called is determined at run time; see late binding. private access - the specifier limiting outside access only to data member or member functions of the same class, or to member functions marked as friends of the class. Protects against accidental or unintended data modification. A derived class inherits all its members as private from a private base class, meaning such a derived class is not considered a subtype of the base class. (USG). protected access - same class member protection as private, as seen by client classes , yet accessible by derived classes, i.e., subclasses, as if the member were declared private to them. A subclass can access the member, but only as one of its own private fields. It cannot access a protected field of its parent class via a pointer to the parent class, only via a pointer to itself (or a descendent). (See USG).. public access - specifier for complete outside access to the member function or data member, limited only by scope. The default access. "Use no public or protected members that aren't functions." (USG). preprocessor directive - e.g., #define and #include. Don't use #defines as substitutes for numerical value consts and enums. reference variable - a parameter passed by address reference, without using pointers, by using the ampersand ('&'). Best for large objects. If the referenced type disagrees with the type of reference variable, the compiler creates and uses a temporary variable, with a warning. "A pointer must be dereferenced to access what it points to, but a reference can be used as is, and acts as a synonym for the object it refers to, both for fetching and storing. ... The entity to which a reference refers may only be set when it is created." (USG; see also pointers vs. references). resolving - resolving a function call is the process of inserting the address (or other reference) of the function at the point where the function is called. When the program executes, the function is executed by performing an assembly language call to that address. (CIO p. 18). root base class - in multiple inheritance, the parent class common to two base classes from which a single class is derived. rvalue - the right-hand side of the assignment operator (=) equation, which is evaluated and copied into the lvalue, or left-hand side. scope - Generally, the domain of objects and calls within which an object can exist. A struct name or enum in an inner scope can obscure a global of the same name in an outer scope. In C++, enum constants embedded in a struct def have the same scope as that struct's fields. scope resolution operator (::) - operator telling compiler to look outside the current block for variable of the same name (e.g., a global, or a member function of a base class.) signature - a function's name and parameter list. See function name overloading. smart pointer - chain overload of the -> (member access) operator to exploit fact left-hand operand requires a pointer return. Each -> overloading function evaluates some criteria, returning an object if the search should continue, or a pointer if the end condition has been met. static member - like a global variable whose scope is limited to the class in which it is declared. Especially true if declared as private or protected. static data member - shared by all objects of a class for each instantiation of that template class. All static data members are defined within the scope of the file in which they exist, by prefixing the definition with a template specification. The def should appear in that .cp file, not in the header. Like globals, automatically initialized to 0. static member function - a member function declared as static; can access and modify static data members; cannot be of type const or virtual. string constant - zero or more chars surrounded by double quotes. structure - an object "consisting of a sequence of named members of various types" (K&R), typically containing one or more data members, and/or member functions which specify the list. May not contain a member of incomplete type. See also struct, class, union. struct - Structure; keyword whose default structure class is public. subclass - a derived class. subscript operator: [ ] - an overloadable operator always telling the compiler the referent is an element of a subscripted variable or array. tag - a type specifier of the form struct-or-union identifier {struct-declaration-list} declares the identifier to be the tag of the structure or union specified by the list (K&R p.212); loosely, a struct name. template - keyword class declarations which are expanded by compiler into full class declarations, when an object of its possible classes is declared, and the template argument list is specified with the class name. Allows declaration of a class, without specifying the type of one or more data members or parameters to a function. One template of class Array could be used to create long, short or char arrays, for example. this object pointer - returns the pointer to or address of a current object without naming it explicitly. typedef - creates new var type from existing var type. Not the same as abstract data typing. See also alias. Use typedefs to isolate "(gasp! naked C types" (USG); don't use primitive C data types in your declarations, in case implementation ever changes. Declare a type that represents the abstract concept you want to represent (also from USG): instead of
use (for example)
union - object declared to use same block of memory in more than one way, i.e., union short_or_long. variable
declaration - a type, followed by a name, e.g., int A; virtual function - use virtual keyword in base class member function to tell compiler to call the overriding function instead of the base function. A pointer to a subclass may be passed in a polymorphic fashion where a pointer to the class is expected (USG). The virtual base class is implemented as a pointer to the derived class. (CIO p.397). See also override. virtual base class - It's called by dereferencing the pointer or referencing the base class; the compiler follows the derivation chain from the root to the most derived class and looks at each level for a match. The lowest-level matching function is the one called. Generally, mark as virtual all direct descendants of the virtual base class. The compiler will ignore all member initialization references to the root class constructor, except the deepest one.
Annotated BibliographyCIO - C++ Inside & Out, Bruce Eckel, Osborne ISBN 0-07-881809-5, © 1993 CRS - C++ Reference Special Pocket Edition, Mike Lottridge, PCI Publishing, ISBN 0-9635330-2-9, © 1993. Just what it says. A concise pocket reference. Very useful as learning tool for grasping and relating concepts; helpful suggestions and cross-referencing. Assumes C++ knowledge. Treats fundamentals and programming strategy. LCM - Learn C++ On The Macintosh, Dave Mark, Addison-Wesley, ISBN 0-201-62204-1, © 1993. A "hands-on" primer with canned source code and line-by-line analysis in each chapter and lesson. Breezily glib on theory, but a good way to get going, with exposure to the fundamental and remarkable "heavy" C++ features. Good reference section with excellent Unofficial Style Guide appendix. Runs on Symantec THINK C++ or reduced tutorial version THIN C++ (included with lessons, 1 diskette). K&R- The C Programming Language, Second (ANSI) Edition, Brian W. Kernighan, Dennis M. Ritchie, Prentice Hall, ISBN 0-13-110370-9. If just one book could win title to the claim "definitive standard", "K&R" is it. Used everywhere, K&R"develops" C theory and implementation as both a step-by-step textbook, and as an authoritative standard. Definition-oriented, builds hierarchically on concepts previously covered. Thin, precise, "compacted", offers copious exercises and on-the-fly assignments. The reader builds working code and practical programs. More in this book than others four times its size. Professionals refer to it again and again. This book is to C what "The Mac Is Not A Typewriter" is to desktop publishing, in spades: if you are afraid of books like this, all the more reason to acquire it and go through the exercises. USG - Unofficial C++ Style Guide, Dave Goldsmith and Jack Palevich, reprinted from develop, The Apple Technical Journal, Issue 2, April 1990, in Appendix G (LCM) by Dave Marks. What happens to your code after it's published or turned over to other programmers, when you think you're done with it? "The Apple Way" of doing things; outstandingly concise, common-sensical. Excellent as a tutorial, as well as a hands-on guide. Explains not only how the working concepts and conventions are used, but why, and what they're good for and protect us against. Even if you already know C++, or program exclusively for the 486 or Pentium, and can't find a copy of Unofficial C++ Style Guide, Mark's text might be worth picking up just for the USG. 14 PAGES. assembled by Alex Forbes rev 10/29/95 10:50 PM Suggestions, comments, corrections, contributions? Please E-mail if you find this reference useful. Last updated October 30, 1995 |
|
|