|
1 | 1 | ---
|
2 |
| -description: "Learn more about: Inheritance (C++)" |
3 |
| -title: "Inheritance (C++)" |
| 2 | +title: "Inheritance (C++)" |
| 3 | +description: "Learn more about: Inheritance (C++)" |
4 | 4 | ms.date: "11/04/2016"
|
5 | 5 | helpviewer_keywords: ["derived classes [C++]", "derived classes [C++], about derived classes", "classes [C++], derived"]
|
6 |
| -ms.assetid: 3534ca19-d9ed-4a40-be1b-b921ad0e6956 |
7 | 6 | ---
|
8 |
| -# Inheritance (C++) |
| 7 | +# Inheritance (C++) |
9 | 8 |
|
10 | 9 | This section explains how to use derived classes to produce extensible programs.
|
11 | 10 |
|
12 | 11 | ## Overview
|
13 | 12 |
|
14 |
| -New classes can be derived from existing classes using a mechanism called "inheritance" (see the information beginning in [Single Inheritance](../cpp/single-inheritance.md)). Classes that are used for derivation are called "base classes" of a particular derived class. A derived class is declared using the following syntax: |
| 13 | +New classes can be derived from existing classes using a mechanism called "inheritance" (see the information beginning in [Single Inheritance](single-inheritance.md)). Classes that are used for derivation are called "base classes" of a particular derived class. A derived class is declared using the following syntax: |
15 | 14 |
|
16 | 15 | ```cpp
|
17 |
| -class Derived : [virtual] [access-specifier] Base |
| 16 | +class DerivedSingleBase : [virtual] [access-specifier] Base |
18 | 17 | {
|
19 |
| - // member list |
| 18 | + // member list |
20 | 19 | };
|
21 |
| -class Derived : [virtual] [access-specifier] Base1, |
22 |
| - [virtual] [access-specifier] Base2, . . . |
| 20 | + |
| 21 | +class DerivedMultipleBases : [virtual] [access-specifier] Base1, |
| 22 | + [virtual] [access-specifier] Base2, ... |
23 | 23 | {
|
24 |
| - // member list |
| 24 | + // member list |
25 | 25 | };
|
26 | 26 | ```
|
27 | 27 |
|
28 |
| -After the tag (name) for the class, a colon appears followed by a list of base specifications. The base classes so named must have been declared previously. The base specifications may contain an access specifier, which is one of the keywords **`public`**, **`protected`** or **`private`**. These access specifiers appear before the base class name and apply only to that base class. These specifiers control the derived class's permission to use to members of the base class. See [Member-Access Control](../cpp/member-access-control-cpp.md) for information on access to base class members. If the access specifier is omitted, the access to that base is considered **`private`**. The base specifications may contain the keyword **`virtual`** to indicate virtual inheritance. This keyword may appear before or after the access specifier, if any. If virtual inheritance is used, the base class is referred to as a virtual base class. |
| 28 | +After the tag (name) for the class, a colon appears followed by a list of base specifications. The base classes so named must have been declared previously. The base specifications may contain an access specifier, which is one of the keywords [**`public`**](public-cpp.md), [**`protected`**](protected-cpp.md) or [**`private`**](private-cpp.md). These access specifiers appear before the base class name and apply only to that base class. These specifiers control the derived class's permission to use members of the base class. See [Member-Access Control](member-access-control-cpp.md) for information on access to base class members. If the access specifier is omitted, the access to that base is considered **`private`**. The base specifications may contain the keyword [**`virtual`**](virtual-cpp.md) to indicate virtual inheritance. This keyword may appear before or after the access specifier, if any. If virtual inheritance is used, the base class is referred to as a virtual base class. |
29 | 29 |
|
30 |
| -Multiple base classes can be specified, separated by commas. If a single base class is specified, the inheritance model is [Single inheritance](../cpp/single-inheritance.md). If more than one base class is specified, the inheritance model is called [Multiple inheritance](../cpp/multiple-base-classes.md). |
| 30 | +Multiple base classes can be specified, separated by commas. If a single base class is specified, the inheritance model is [Single inheritance](single-inheritance.md). If more than one base class is specified, the inheritance model is called [Multiple inheritance](multiple-base-classes.md). |
31 | 31 |
|
32 | 32 | The following topics are included:
|
33 | 33 |
|
34 |
| -- [Single inheritance](../cpp/single-inheritance.md) |
| 34 | +- [Single inheritance](single-inheritance.md) |
| 35 | + |
| 36 | +- [Multiple base classes](multiple-base-classes.md) |
| 37 | + |
| 38 | +- [Virtual functions](virtual-functions.md) |
35 | 39 |
|
36 |
| -- [Multiple base classes](../cpp/multiple-base-classes.md) |
| 40 | +- [Explicit overrides](explicit-overrides-cpp.md) |
37 | 41 |
|
38 |
| -- [Virtual functions](../cpp/virtual-functions.md) |
| 42 | +- [Abstract classes](abstract-classes-cpp.md) |
39 | 43 |
|
40 |
| -- [Explicit overrides](../cpp/explicit-overrides-cpp.md) |
| 44 | +- [Summary of scope rules](summary-of-scope-rules.md) |
41 | 45 |
|
42 |
| -- [Abstract classes](../cpp/abstract-classes-cpp.md) |
| 46 | +**Microsoft Specific** |
43 | 47 |
|
44 |
| -- [Summary of scope rules](../cpp/summary-of-scope-rules.md) |
| 48 | +The [`__super`](super.md) and [`__interface`](interface.md) keywords are documented in this section. |
45 | 49 |
|
46 |
| -The [__super](../cpp/super.md) and [__interface](../cpp/interface.md) keywords are documented in this section. |
| 50 | +**END Microsoft Specific** |
47 | 51 |
|
48 | 52 | ## See also
|
49 | 53 |
|
50 |
| -[C++ Language Reference](../cpp/cpp-language-reference.md) |
| 54 | +[C++ Language Reference](cpp-language-reference.md) |
0 commit comments