Data members (C++ only)
Data members include members that are declared with any of the fundamental types, as well as other types, including pointer, reference, array types, bit fields, and user-defined types. You can declare a data member the same way as a variable, except that explicit initializers are not allowed inside the class definition. However, a const static data member of integral or enumeration type may have an explicit initializer.
If an array is declared as a nonstatic class member, you must specify all of the dimensions of the array.
A class can have members that are of a class type or are pointers or references to a class type. Members that are of a class type must be of a class type that has been previously declared. An incomplete class type can be used in a member declaration as long as the size of the class is not needed. For example, a member can be declared that is a pointer to an incomplete class type.
X
cannot have a member that is
of type X
, but it can contain pointers to X
,
references to X
, and static objects of X
.
Member functions of X
can take arguments of type X
and
have a return type of X
. For example: class X
{
X();
X *xptr;
X &xlref;
X &&xrref;
static X xcount;
X xfunc(X);
};