A data object is a region of storage that contains a value or group of values. Each value can be accessed using its identifier or a more complex expression that refers to the object. In addition, each object has a unique data type. The data type of an object determines the storage allocation for that object and the interpretation of the values during subsequent access. It is also used in any type checking operations. Both the identifier and data type of an object are established in the object declaration.
An instance of a class type is commonly called a class object. The individual class members are also called objects.
Data object | Basic | Compound | Built- |
User- |
Scalar | Aggregate |
---|---|---|---|---|---|---|
integer types | + | + | + | |||
floating-point types1 | + | + | + | |||
character types | + | + | ||||
Booleans | + | + | + | |||
void type | +2 | + | + | |||
pointers | + | + | + | |||
arrays | + | + | + | |||
structures | + | + | + | |||
unions | + | + | ||||
enumerations | + | + | see note3 | |||
classes | + | + | + | |||
vector types | + | + |
However, if an array size is specified by [*], indicating a variable length array, the size is considered as having been specified, and the array type is then considered a complete type. For more information, see Variable length arrays.
void *incomplete_ptr;
struct dimension linear; /* no previous definition of dimension */
A composite type is constructed from two compatible types. Determining the resultant composite type for two compatible types is similar to following the usual binary conversions of integral types when they are combined with some arithmetic operators.
Obviously, two types that are identical are compatible; their composite type is the same type. Less obvious are the rules governing type compatibility of non-identical types, user-defined types, type-qualified types, and so on. Type specifiers discusses compatibility for basic and user-defined types in C.
A separate notion of type compatibility as distinct from being of the same type does not exist in C++. Generally speaking, type checking in C++ is stricter than in C: identical types are required in situations where C would only require compatible types.