Inheritance keywords

Microsoft Specific

class class-name
class __single_inheritance class-name
class __multiple_inheritance class-name
class __virtual_inheritance class-name

where:

class-name
The name of the class being declared.

C++ allows you to declare a pointer to a class member before the definition of the class. For example:

class S;
int S::*p;

In the code above, p is declared to be a pointer to integer member of class S. However, class S hasn't been defined yet in this code; it's only been declared. When the compiler encounters such a pointer, it must make a generalized representation of the pointer. The size of the representation is dependent on the inheritance model specified. There are three ways to specify an inheritance model to the compiler:

  • At the command line using the /vmg switch

  • Using the pointers_to_members pragma

  • Using the inheritance keywords __single_inheritance, __multiple_inheritance, and __virtual_inheritance. This technique controls the inheritance model on a per-class basis.

    Note

    If you always declare a pointer to a member of a class after defining the class, you don't need to use any of these options.

If you declare a pointer to a class member before the class is defined, it can negatively affect the size and speed of the resulting executable file. The more complex the inheritance used by a class, the greater the number of bytes required to represent a pointer to a member of the class. And, the larger the code required to interpret the pointer. Single (or no) inheritance is least complex, and virtual inheritance is most complex. Pointers to members you declare before the class is defined always use the largest, most complex representation.

If the example above is changed to:

class __single_inheritance S;
int S::*p;

then no matter the command-line options or pragmas you specify, pointers to members of class S will use the smallest possible representation.

Note

The same forward declaration of a class pointer-to-member representation should occur in every translation unit that declares pointers to members of that class, and the declaration should occur before the pointers to members are declared.

For compatibility with previous versions, _single_inheritance, _multiple_inheritance, and _virtual_inheritance are synonyms for __single_inheritance, __multiple_inheritance, and __virtual_inheritance unless compiler option /Za (Disable language extensions) is specified.

END Microsoft Specific

See also

Keywords