-
Book Overview & Buying
-
Table Of Contents
The C++ Workshop
By :
A container is a data structure consisting of multiple instances of the same data type. For instance, a C++ array is a simple kind of container. The type of array says what kind of data it contains. An array has a fixed size specified at compile time. A dynamic array is a container that has a fixed type and an arbitrary size, but the size is fixed when the container is created.
Using dynamic class instances, each containing a single pointer, a program can create a container that can grow to a size that is not predetermined. Each entry in a container is a class (or struct) instance. The class has a payload (a member called value_, an int in the following example) and a pointer member (called next_ in the following example), which refers to the next instance in the container. The class definition looks like this:
struct numeric_item
{
int value_;
numeric_item* next_;
};
Dynamically created instances...