Chapter Summary
C++ provides several specialized facilities that are tailored to particular kinds of problems.
Some applications need to take control of how memory is allocated. They can do so by defining their own versions—either class specific or global—of the library operator new
and operator delete
functions. If the application defines its own versions of these functions, new
and delete
expressions will use the application-defined version.
Some programs need to directly interrogate the dynamic type of an object at run time. Run-time type identification (RTTI) provides language-level support for this kind of programming. RTTI applies only to classes that define virtual functions; type information for types that do not define virtual functions is available but reflects the static type.
When we define a pointer to a class member, the pointer type also encapsulates the type of the class containing the member to which the pointer points. A pointer to member may be bound to any member of the class that has the appropriate type. When we dereference a pointer to member, we must supply an object from which to fetch the member.
C++ defines several additional aggregate types:
- Nested classes, which are classes defined in the scope of another class. Such classes are often defined as implementation classes of their enclosing class.
union
s are a special kind of class that may define several data members, but at any point in time, only one member may have a value.union
s are most often nested inside another class type.- Local classes, which are defined inside a function. All members of a local class must be defined in the class body. There are no
static
data members of a local class.
C++ also supports several inherently nonportable features, including bit-fields and volatile
, which make it easier to interface to hardware, and linkage directives, which make it easier to interface to programs written in other languages.