Code Containers
One aspect of C++ that makes it very powerful is its ability to package code in several different ways.
Table 7.1 defines some terms that are used to describe containers of code. The table is arranged (approximately) in order of increasing granularity from top to bottom.
Term |
Visible attributes |
Description |
---|---|---|
class |
class Classname { body } ; |
A collection of functions and data members, and descriptions of its lifecycle management (constructors and destructors) |
namespace |
namespace name { body } ; |
A collection of declarations and definitions, of classes, functions and static members, perhaps spanning multiple files |
header file |
.h |
Class definitions, template definitions, function declarations (with default argument definitions), inline definitions, static object declarations |
source code module |
.cpp |
Function definitions, static object definitions |
compiled "object" module |
.o or .obj |
Each .cpp module is compiled into a binary module as an intermediate step in building a library or executable. |
library |
.lib or .la (+ .so or .dll if dynamic) |
An indexed collection of object files linked together. No main() function must exist in any code module in a library. |
devel package |
lib + header files |
A library along with accompanying header files |
application |
.exe on windows, no particular extension on *nix |
A collection of object files, linked with libraries, to form an application. Contains exactly one function definition called main(). |
Reusing Other Libraries
|