Defining Class Types
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

Defining Class Types

Class types are defined using class-specifiers. Class types can be declared using elaborated-type-specifiers as shown in Type Specifiers.

Grammar

class-specifier :
class-head { member-listopt }
class-head :
class-key imodelopt identifieropt base-specopt
class-key imodelopt class-nameopt base-specopt
class-key :
class
struct
union
imodel :
__declspec

Class names are introduced as identifiers immediately after the compiler processes them (before entry into the class body); they can be used to declare class members. This allows declaration of self-referential data structures, such as the following:

// defining_class_types.cpp
class Tree
{
public:
    void *Data;
    Tree *Left;
    Tree *Right;
};

int main()
{
}

See Also

Overview of Classes

Show:
© 2016 Microsoft