Skip to content

Latest commit

 

History

History
66 lines (48 loc) · 3.14 KB

inheritance-keywords.md

File metadata and controls

66 lines (48 loc) · 3.14 KB
title ms.custom ms.date ms.technology ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid author ms.author ms.workload
Inheritance Keywords | Microsoft Docs
11/04/2016
cpp-language
language-reference
__multiple_inheritance
__single_inheritance_cpp
__virtual_inheritance_cpp
__virtual_inheritance
__multiple_inheritance_cpp
__single_inheritance
C++
__single_inheritance keyword [C++]
declaring derived classes [C++]
keywords [C++], inheritance keywords
__multiple_inheritance keyword [C++]
__virtual_inheritance keyword [C++]
inheritance, declaring derived classes
derived classes [C++], declaring
inheritance, keywords
bb810f56-7720-4fea-b8b6-9499edd141df
mikeblome
mblome
cplusplus

Inheritance Keywords

Microsoft Specific

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 prior to 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 has not yet been defined in this code; it has 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 four ways to specify an inheritance model to the compiler:

  • In the IDE under Pointer-to-member representation

  • 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.

Declaring a pointer to a member of a class prior to the class definition affects 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 inheritance is least complex, and virtual inheritance is most complex.

If the example above is changed to:

class __single_inheritance S;  
int S::*p;  

regardless of command-line options or pragmas, 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.

END Microsoft Specific

See also

Keywords