< Day Day Up >
Terminology
There is a small C++ vocabulary that every programmer should understand. The following terms are important
enough that it is worth making sure we agree on what they mean.
A declaration tells compilers about the name and type of something, but it omits certain details. These are
declarations:
extern int x; // object declaration
std::size_t numDigits(int number); // function declaration
class Widget; // class declaration
template<typename T> // template declaration
class GraphNode; // (see Item 42 for info on
// the use of "typename")
Note that I refer to the integer x as an "object," even though it's of built-in type. Some people reserve the name
"object" for variables of user-defined type, but I'm not one of them. Also note that the function numDigits' return
type is std::size_t, i.e., the type size_t in namespace std. That namespace is where virtually everything in
C++'s standard library is located. However, because C's standard library (the one from C89, to be precise) can also
be used in C++, symbols inherited from C (such as size_t) may exist at global scope, inside std, or both,
depending on which headers have been #included. In this book, I assume that C++ headers have been
#included, and that's why I refer to std::size_t instead of just size_t. When referring to components of
the standard library in prose, I typically omit references to std, relying on you to recognize that things like size_t,
vector, and cout are in std. In example code, I always include std, because real code won't compile without it.
size_t, by the way, is just a typedef for some unsigned type that C++ uses when counting things (e.g., the number
of characters in a char*-based string, the number of elements in an STL container, etc.). It's also the type taken by
the operator[] functions in vector, deque, and string, a convention we'll follow when defining our own
operator[] functions in Item 3.
Each function's declaration reveals its signature, i.e., its parameter and return types. A function's signature is the
same as its type. In the case of numDigits, the signature is std::size_t (int), i.e., "function taking an
int and returning a std::size_t." The official C++ definition of "signature" excludes the function's return type,
but in this book, it's more useful to have the return type be considered part of the signature.
A definition provides compilers with the details a declaration omits. For an object, the definition is where compilers
set aside memory for the object. For a function or a function template, the definition provides the code body. For a
class or a class template, the definition lists the members of the class or template:
int x; // object definition
std::size_t numDigits(int number) // function definition.