Udostępnij za pośrednictwem


Defining Class Types

Class types are defined using class specifiers. Class types can be declared using elaborated type specifiers as shown in Type Specifiers. The class specifier consists of:

  • The class, struct or union keyword.

  • The class heading includes the class name and the applicable template heading.

  • Optionally, a colon and the base list which identifies the base classes that the class being defined inherits from.

  • Braces ({}) containing the class member declarations.

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
// compile with: /c
class Tree
{
public:
   void *Data;
   Tree *Left;
   Tree *Right;
};

See Also

Reference

Overview of Classes

Change History

Date

History

Reason

October 2008

Deleted repeated text.

Customer feedback.