tmp/tmppq03e4fx/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### General <a id="class.derived.general">[[class.derived.general]]</a>
|
| 2 |
+
|
| 3 |
+
A list of base classes can be specified in a class definition using the
|
| 4 |
+
notation:
|
| 5 |
+
|
| 6 |
+
``` bnf
|
| 7 |
+
base-clause:
|
| 8 |
+
':' base-specifier-list
|
| 9 |
+
```
|
| 10 |
+
|
| 11 |
+
``` bnf
|
| 12 |
+
base-specifier-list:
|
| 13 |
+
base-specifier '...'ₒₚₜ
|
| 14 |
+
base-specifier-list ',' base-specifier '...'ₒₚₜ
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
``` bnf
|
| 18 |
+
base-specifier:
|
| 19 |
+
attribute-specifier-seqₒₚₜ class-or-decltype
|
| 20 |
+
attribute-specifier-seqₒₚₜ virtual access-specifierₒₚₜ class-or-decltype
|
| 21 |
+
attribute-specifier-seqₒₚₜ access-specifier virtualₒₚₜ class-or-decltype
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
``` bnf
|
| 25 |
+
class-or-decltype:
|
| 26 |
+
nested-name-specifierₒₚₜ type-name
|
| 27 |
+
nested-name-specifier template simple-template-id
|
| 28 |
+
decltype-specifier
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
``` bnf
|
| 32 |
+
access-specifier:
|
| 33 |
+
private
|
| 34 |
+
protected
|
| 35 |
+
public
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
The optional *attribute-specifier-seq* appertains to the
|
| 39 |
+
*base-specifier*.
|
| 40 |
+
|
| 41 |
+
The component names of a *class-or-decltype* are those of its
|
| 42 |
+
*nested-name-specifier*, *type-name*, and/or *simple-template-id*. A
|
| 43 |
+
*class-or-decltype* shall denote a (possibly cv-qualified) class type
|
| 44 |
+
that is not an incompletely defined class [[class.mem]]; any
|
| 45 |
+
cv-qualifiers are ignored. The class denoted by the *class-or-decltype*
|
| 46 |
+
of a *base-specifier* is called a *direct base class* for the class
|
| 47 |
+
being defined. The lookup for the component name of the *type-name* or
|
| 48 |
+
*simple-template-id* is type-only [[basic.lookup]]. A class `B` is a
|
| 49 |
+
base class of a class `D` if it is a direct base class of `D` or a
|
| 50 |
+
direct base class of one of `D`’s base classes. A class is an
|
| 51 |
+
*indirect base class* of another if it is a base class but not a direct
|
| 52 |
+
base class. A class is said to be (directly or indirectly) *derived*
|
| 53 |
+
from its (direct or indirect) base classes.
|
| 54 |
+
|
| 55 |
+
[*Note 1*: See [[class.access]] for the meaning of
|
| 56 |
+
*access-specifier*. — *end note*]
|
| 57 |
+
|
| 58 |
+
Members of a base class are also members of the derived class.
|
| 59 |
+
|
| 60 |
+
[*Note 2*: Constructors of a base class can be explicitly inherited
|
| 61 |
+
[[namespace.udecl]]. Base class members can be referred to in
|
| 62 |
+
expressions in the same manner as other members of the derived class,
|
| 63 |
+
unless their names are hidden or ambiguous [[class.member.lookup]]. The
|
| 64 |
+
scope resolution operator `::` [[expr.prim.id.qual]] can be used to
|
| 65 |
+
refer to a direct or indirect base member explicitly, even if it is
|
| 66 |
+
hidden in the derived class. A derived class can itself serve as a base
|
| 67 |
+
class subject to access control; see [[class.access.base]]. A pointer
|
| 68 |
+
to a derived class can be implicitly converted to a pointer to an
|
| 69 |
+
accessible unambiguous base class [[conv.ptr]]. An lvalue of a derived
|
| 70 |
+
class type can be bound to a reference to an accessible unambiguous base
|
| 71 |
+
class [[dcl.init.ref]]. — *end note*]
|
| 72 |
+
|
| 73 |
+
The *base-specifier-list* specifies the type of the *base class
|
| 74 |
+
subobjects* contained in an object of the derived class type.
|
| 75 |
+
|
| 76 |
+
[*Example 1*:
|
| 77 |
+
|
| 78 |
+
``` cpp
|
| 79 |
+
struct Base {
|
| 80 |
+
int a, b, c;
|
| 81 |
+
};
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
``` cpp
|
| 85 |
+
struct Derived : Base {
|
| 86 |
+
int b;
|
| 87 |
+
};
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
``` cpp
|
| 91 |
+
struct Derived2 : Derived {
|
| 92 |
+
int c;
|
| 93 |
+
};
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
Here, an object of class `Derived2` will have a subobject of class
|
| 97 |
+
`Derived` which in turn will have a subobject of class `Base`.
|
| 98 |
+
|
| 99 |
+
— *end example*]
|
| 100 |
+
|
| 101 |
+
A *base-specifier* followed by an ellipsis is a pack expansion
|
| 102 |
+
[[temp.variadic]].
|
| 103 |
+
|
| 104 |
+
The order in which the base class subobjects are allocated in the most
|
| 105 |
+
derived object [[intro.object]] is unspecified.
|
| 106 |
+
|
| 107 |
+
[*Note 3*: A derived class and its base class subobjects can be
|
| 108 |
+
represented by a directed acyclic graph (DAG) where an arrow means
|
| 109 |
+
“directly derived from” (see Figure [[fig:class.dag]]). An arrow
|
| 110 |
+
need not have a physical representation in memory. A DAG of subobjects
|
| 111 |
+
is often referred to as a “subobject lattice”. — *end note*]
|
| 112 |
+
|
| 113 |
+
<a id="fig:class.dag"></a>
|
| 114 |
+
|
| 115 |
+
![Directed acyclic graph \[fig:class.dag\]](images/figdag.svg)
|
| 116 |
+
|
| 117 |
+
[*Note 4*: Initialization of objects representing base classes can be
|
| 118 |
+
specified in constructors; see [[class.base.init]]. — *end note*]
|
| 119 |
+
|
| 120 |
+
[*Note 5*: A base class subobject can have a layout different from the
|
| 121 |
+
layout of a most derived object of the same type. A base class subobject
|
| 122 |
+
can have a polymorphic behavior [[class.cdtor]] different from the
|
| 123 |
+
polymorphic behavior of a most derived object of the same type. A base
|
| 124 |
+
class subobject can be of zero size; however, two subobjects that have
|
| 125 |
+
the same class type and that belong to the same most derived object
|
| 126 |
+
cannot be allocated at the same address [[intro.object]]. — *end note*]
|
| 127 |
+
|