7.1. Code Containers

[ fromfile: granularities.xml id: granularities ]

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.

Table 7.1. Reusable Components

TermVisible attributesDescription
class class Classname { body } ; A collection of functions and data members, and descriptions of its lifecycle management (constructors and destructors)
namespace namespace nname { body } ; A collection of declarations and definitions, of classes, functions and static members, perhaps spanning multiple files
header file.hclass definitions, template definitions, function declarations (with default argument definitions), inline definitions, static object declarations
source code module.cppFunction 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 packagelib + header files A library along with accompanying header files
application.exe on windows, no particular extension on *nixA collection of object files, linked with libraries, to form an application. Contains exactly one function definition called main().