Defining Class Types
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Defining Class Types

Updated: October 2008

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
   void *Data;
   Tree *Left;
   Tree *Right;




October 2008

Deleted repeated text.

Customer feedback.

© 2015 Microsoft