The terminology used by this book is as defined by the "Draft Standard for The Programming Language C++" with some additions that are presented below.
An abstract base class is a class with at least one pure virtual member function.
An access function (accessor) is a member function that returns a value and that does not modify the object's state.
A built-in type is one of the types defined by the language, such as int, short, char and bool.
A class invariant is a condition that defines all valid states for an object. An class invariant is both a pre- and postcondition to a member function of the class.
A program is const correct if it has correctly declared functions, parameters, return values, variables and member functions as const.
The copy assignment operator of a class is the assignment operator taking a reference to an object of the same class as parameter.
The copy constructor of a class is the constructor taking a reference to an object of the same class as parameter.
A declarative region is the largest part of a program where a name declared in that region can be used with its unqualified name.
The direct base class of a class is the classes explicitly mentioned as base classes in its definition. All other base classes are indirect base classes .
A member function call is dynamically bound if different functions will be called depending on the type of the object operated upon.
Encapsulation allows a user to only depend on the class interface, and not upon its implementation.
A class is exception safe if its objects do not loose any resources, do not invalidate their class invariant or terminate the application when they end their life-time because of an exception.
An explicit type conversion is when an object is converted from one type to another, and where you have to explicitly write the resulting type.
An object with file scope is only accessible to functions within the same translation unit.
The
flow control primitives
are:
if-else
,
switch
,
do-while
,
while
and
for
.
A forwarding function is a function which does nothing more than call another function.
An object or type is in global scope if it can be accessed from within any function of a program.
Code with Implementation-defined behavior is completely legal C++, but compilers may differ. The compiler vendor is required to describe what their particular compiler does with such code.
An implicit type conversion is when an object is converted from one type to another, and where you don't have to explicitly write the resulting type.
An inline definition file is a file that only contains definitions of inline functions.
A modifying function (modifier) is a member function that changes the value of at least one data member.
A language supports object-oriented programming if it provides encapsulation, inheritance and polymorphism.
Polymorphism means that an expression can have many different interpretations depending on the context. This means that the same piece of code can be used to operate upon many types of objects as provided by e.g. dynamic binding and parameterization.
A postcondition is a condition that must be true on exit from a member function, if the precondition was valid on entry to that function. A class is implemented correctly if postconditions are never false.
A precondition is a condition that must be true on entry to a member function. A class is used correctly if preconditions are never false.
A resource is something that more than one program needs, but for which there is a limit for how much that is available. Resources can be acquired and released.
A header file is self contained if nothing more than its inclusion is needed to use the full interface of a class.
The signature of a function is defined by its return type, its parameter types and their order, and the access given the object operated upon (const or volatile).
Slicing means that the data added by a subclass is discarded when an object of a subclass is passed or returned by value to or from a function expecting a base class object.
Stack unwinding is the process during exception handling when the destructor is called for all local objects between the place where the exception was thrown and where it is caught.
The state of an object is the data members of the object, and possibly also other data which the object has access to, which affects the observable behavior of the object.
Substitutability means that a derived class object can be used in a context expecting an object of any class derived from one its base class.
An template definition file is a file that only contains definitions of non-inline template functions.
A translation unit is the result of merging a implementation file with all its headers and header files.
Code with undefined behavior is not correct C++. The standard does not specify what a compiler shall do with such code. It may ignore the problem completely, issue an error or something else.
Code with unspecified behavior is completely legal C++, but compilers may differ. The compiler vendor is not required to describe what their particular compiler does with such code.
A user-defined conversion is a conversion from one type to another introduced by a programmer, i.e. not one of the conversions defined by the language. Such user-defined conversions are either a non- explicit constructor taking only one parameter, or a conversion operator.
A virtual table is an array of pointers to all virtual member functions of a class. Many compilers generate such tables to implement dynamic binding of virtual functions.
Rec 1.2 Use English names for identifiers.
Rec 1.3 Be consistent when naming functions, types, variables and constants.
Rec 1.4 Only namespace names should be global.
Rec 1.5 Do not use global using declarations and using directives inside header files.
Rec 1.6 Prefixes should be used to group macros.
Rec 1.7 Group related files by using a common prefix in the file name.
Rule 2.1 Each header file should be self-contained.
Rule 2.2 Avoid unnecessary inclusion.
Rule 2.3 Enclose all code in header files within include guards.
Rec 2.4 Definitions for inline member functions should be placed in a separate file.
Rec 2.5 Definitions for all template functions of a class should be placed in a separate file.
Rec 3.1 Each file should contain a copyright comment.
Rec 3.2 Each file should contain a comment with a short description of the file content.
Rec 3.3 Every file should declare a local constant string that identifies the file.
Rec 3.4 Use // for comments.
Rule 4.1 Do not change a loop variable inside a for -loop block.
Rec 4.2 Update loop variables close to where the loop-condition is specified.
Rec 4.3 All flow control primitives ( if, else, while, for, do, switch and case ) should be followed by a block, even if it is empty.
Rec 4.4 Statements following a case label should be terminated by a statement that exits the switch statement.
Rec 4.5 All switch statements should have a default clause.
Rule 4.6 Use break and continue instead of goto .
Rec 5.1 Declare and initialize variables close to where they are used.
Rec 5.2 If possible, initialize variables at the point of declaration.
Rec 5.3 Declare each variable in a separate declaration statement.
Rec 5.4 Literals should only be used in the definition of constants and enumerations.
Rec 5.5 Initialize all data members.
Rule 5.6 Let the order in the initializer list be the same as the order of declaration in the header file. First base classes, then data members.
Rec 5.7 Do not use or pass this in constructor initializer lists.
Rec 5.8 Avoid unnecessary copying of objects that are costly to copy.
Rule 5.9 A function must never return, or in any other way give access to, references or pointers to local variables outside the scope in which they are declared.
Rec 5.10 If objects of a class should never be copied, then the copy constructor and the copy assignment operator should be declared private and not implemented.
Rec 5.11 A class that manages resources should declare a copy constructor, a copy assignment operator, and a destructor.
Rule 5.12 Copy assignment operators should be protected from doing destructive actions if an object is assigned to itself.
Rec 6.1 Prefer explicit to implicit type conversions.
Rec 6.2 Use the new cast operators ( dynamic_cast, const_cast, reinterpret_cast and static_cast ) instead of the old-style casts, unless portability is an issue.
Rec 6.3 Do not cast away const.
Rule 6.4 Declare a data member as mutable if it must be modified by a const member function.
Rec 7.1 Make simple functions inline.
Rule 7.2 Do not declare virtual member functions as inline .
Rec 7.3 Pass arguments of built-in types by value, unless the function should modify them.
Rec 7.4 Only use a parameter of pointer type if the function stores the address, or passes it to a function that does.
Rec 7.5 Pass arguments of class types by reference or pointer.
Rule 7.6 Pass arguments of class types by reference or pointer, if the class is meant as a public base class.
Rule 7.7 The copy assignment operator should return a non-const reference to the object assigned to.
Rule 7.8 A pointer or reference parameter should be declared const if the function does not change the object bound to it.
Rule 7.9 The copy constructor and copy assignment operator should always have a const reference as parameter.
Rule 7.10 Only use const char -pointers to access string literals.
Rule 7.11 A member function that does not change the state of the program should be declared const .
Rule 7.12 A member function that gives non-const access to the representation of an object must not be declared const .
Rec 7.13 Do not let const member functions change the state of the program.
Rule 7.14 All variants of an overloaded member function should be used for the same purpose and have similar behavior.
Rec 7.15 If you overload one out of a closely-related set of operators, then you should overload the whole set and preserve the same invariants that exist for built-in types.
Rule 7.16 If, in a derived class, you need to override one out of a set of the base class' overloaded virtual member functions, then you should override the whole set, or use using-declarations to bring all of the functions in the base class into the scope of the derived class.
Rule 7.17 Supply default arguments with the function's declaration in the header file, not with the function's definition in the implementation file.
Rule 8.1 delete should only be used with new .
Rule 8.2 delete [] should only be used with new [] .
Rule 8.3 Do not access a pointer or reference to a deleted object.
Rec 8.4 Do not delete this .
Rec 8.5 If you overload operator new for a class, you should have a corresponding overloaded operator delete .
Rec 8.6 Customize the memory management for a class if memory management is an unacceptably-large part of the allocation and deallocation of free store objects of that class.
Rec 9.1 Objects with static storage duration should only be declared within the scope of a class, function or anonymous namespace.
Rule 10.1 Only declare data members private.
Rec 10.2 If a member function returns a pointer or reference, then you should document how it should be used and for how long it is valid.
Rec 10.3 Selection statements ( if and switch ) should be used when the flow of control depends on an object's value, while dynamic binding should be used when the flow of control depends on the object's type.
Rule 10.4 A public base class must either have a public virtual destructor or a protected destructor.
Rule 10.5 If you derive from more than one base classes with the same parent, then that parent should be a virtual base class.
Rec 10.6 Specify classes using preconditions, postconditions, exceptions and class invariants.
Rec 10.7 Use C++ to describe preconditions, postconditions and class invariants.
Rule 10.8 A pointer or reference to an object of a derived class should be possible to use wherever a pointer or reference to a public base class object is used.
Rec 12.1 Check for all errors reported from functions.
Rec 12.2 Use exception handling instead of status values and error codes.
Rec 12.3 Only throw exceptions when a function fails to perform what it is expected to do.
Rec 12.4 Do not throw exceptions as a way of reporting uncommon values from a function.
Rule 12.5 Do not let destructors called during stack unwinding throw exceptions.
Rec 12.6 Constructors of types thrown as exceptions should not themselves throw exceptions.
Rec 12.7 Use objects to manage resources.
Rule 12.8 A resource managed by an object must be released by the object's destructor.
Rec 12.9 Use stack objects instead of free store objects.
Rec 12.10 Before letting any exceptions propagate out of a member function, make certain that the class invariant holds, and if possible leave the state of the object unchanged.
Rec 12.11 Only throw objects of class type.
Rec 12.12 Group related exception types by using inheritance.
Rec 13.1 Use new and delete instead of malloc , calloc , realloc and free .
Rule 13.2 Use the iostream library instead of C-style I/O.
Rule 13.3 Do not use setjmp( ) and longjmp() .
Rec 13.4 Use overloaded functions and chained function calls instead of functions with an unspecified number of arguments.
Rec 14.1 Avoid duplicated code and data.
Rule 14.2 When a public base class has a virtual destructor, each derived class should declare and implement a destructor.
Rule 15.1 Do not depend on undefined, unspecified or implementation-defined parts of the language.
Rule 15.2 Do not depend on extensions to the language or to the standard library.
Rule 15.4 Headers supplied by the implementation should go in <> brackets; all other headers should go in "" quotes.
Rec 15.5 Do not specify absolute directory names in include directives.
Rec 15.6 Include file names should always be treated as case sensitive.
Rule 15.7 Do not make assumptions about the size of or layout in memory of an object.
Rule 15.8 Do not cast a pointer to a shorter quantity to a pointer to a longer quantity.
Rec 15.9 If possible, use plain int to store, pass or return integer values.
Rec 15.10 Do not explicitly declare integral types as signed or unsigned .
Rule 15.11 Make sure all conversions of a value of one type to another of a narrower type do not slice off significant data.
Rec 15.12 Use typedefs or classes to hide the representation of application-specific data types.
Rec 15.13 Always prefix global names (such as externally visible classes, functions, variables, constants, typedefs and enums) if namespace is not supported by the compiler.
Rec 15.14 Use macros to prevent usage of unsupported keywords.
Rec 15.15 Do not reuse variables declared inside a for -loop.
Rec 15.16 Only inclusion of the header file should be needed when using a template.
Rec 15.17 Do not rely on partial instantiation of templates.
Rec 15.18 Do not rely on the lifetime of temporaries.
Rec 15.19 Do not use pragma s.
Rule 15.20 Always return a value from main() .
Rec 15.21 Do not depend on the order of evaluation of arguments to a function.
Style 1.1 Do not mix coding styles within a group of closely related classes.
Style 1.2 In names that consist of more than one word, the words are written together and each word that follows the first begins with an uppercase letter.
Style 1.3 The names of classes, typedefs, and enumerated types should begin with an uppercase letter.
Style 1.4 The names of variables and functions should begin with a lower-case letter.
Style 1.5 Let data members have a "M" as suffix.
Style 1.6 The names of macros should be in uppercase.
Style 1.7 The name of an include guard should be the name of the header file with all illegal characters replaced by underscores and all letters converted to uppercase.
Style 1.8 Do not use characters that can be mistaken for digits, and vice versa.
Style 1.9 Header files should have the extension " .hh ".
Style 1.10 Inline definition files should have the extension " .icc ".
Style 1.11 The names of parameters to functions should be specified in the function declaration if the type name is insufficient to describe the parameter.
Style 1.12 Always provide an access specifier for base classes and data members.
Style 1.13 The public, protected, and private sections of a class should be declared in that order.
Style 1.14 The keyword struct should only be used for a C-style struct.
Style 1.15 Define inline member functions outside the class definition.
Style 1.16 Write unary operators together with their operand.
Style 1.17 Write access operators together with their operands.
Style 1.18 Do not access static members with ' . ' or ' -> '.
abort 138
ambiguous name, multiple inheritance 113
array class, instead of built-in array 164
assert macro 130
conditions to check 120-122, 130-131
auto_ptr 147, 149
bad_exception 156
pointer or reference, using 110, 122
block, after flow control primitive 27-28
break , see switch
allocated with new 88-89
calloc 158
case 28
base class reference 135, 151-153
with ... 135, 146, 154
signed or unsigned 180
signed or unsigned 172
data member access 104-105, 198-199
specification 117, 120-122, 137
preserving in derived class 123
template parameter behavior 125
see also mutable
const_cast , see new-style cast
declared explicit 183
see also new
with exception handling 137, 139
from longer to narrower type 180
access specifier 104-105, 198-199
mutable 53
static 97
default int 189
default , see switch
and new 88
instead of free 158
delete 88-91
compiler-generated destructor 170
delete through base pointer 112
implement base class interface 107-108
overriding member functions 108
called after exception 134, 147
see also delete
do-while , when to use 27
dynamic storage duration, see new
dynamic_cast , see new-style cast
instead of static const int 162
errno 135, 153
errors that cannot be prevented 137-140
status values and error codes 134
unexpected value in switch 29
compared to status value 134-136
representing the type of error 150
translation of status value 137
see also throw
bad_exception 156
one catch for many exceptions 153
recover from exception 147, 154-155
terminate 140
uncaught_exception 140-141
when to throw exception 137-143
exception specification 123, 155-156
to document class interface 155
explicit 183
EXTERNAL_TEMPLATE_DEFINITION 187
false 183
name, template implementation 186
see also inline definition file
flow control primitive 27, 204
free 158
see new and delete
returning reference or pointer 105
returning status value 134-135
if-else 27, 107
implementation-defined behavior 172, 205
char signed or unsigned 179
lifetime of temporary object 187
pragma 188
subtracting with unsigned types 179
private, protected or public 122
replace if-else and switch 107
order, within translation unit 99
passing this 37
inline definition file 15, 205
effect on performance and size 56, 169
conversion from char 178
INT_MAX 179
INT_MIN 179
signed and unsigned 179
compared to stdio 159