tmp/tmpju8fri8d/{from.md → to.md}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
## Multiple base classes <a id="class.mi">[[class.mi]]</a>
|
| 2 |
|
| 3 |
A class can be derived from any number of base classes.
|
| 4 |
|
| 5 |
[*Note 1*: The use of more than one direct base class is often called
|
| 6 |
multiple inheritance. — *end note*]
|
|
@@ -15,13 +15,13 @@ class D : public A, public B, public C { ... };
|
|
| 15 |
```
|
| 16 |
|
| 17 |
— *end example*]
|
| 18 |
|
| 19 |
[*Note 2*: The order of derivation is not significant except as
|
| 20 |
-
specified by the semantics of initialization by constructor
|
| 21 |
-
[[class.base.init]]
|
| 22 |
-
[[class.mem]],
|
| 23 |
|
| 24 |
A class shall not be specified as a direct base class of a derived class
|
| 25 |
more than once.
|
| 26 |
|
| 27 |
[*Note 3*: A class can be an indirect base class more than once and can
|
|
@@ -33,11 +33,11 @@ can be unambiguously referred to. — *end note*]
|
|
| 33 |
|
| 34 |
[*Example 2*:
|
| 35 |
|
| 36 |
``` cpp
|
| 37 |
class X { ... };
|
| 38 |
-
class Y : public X, public X { ... }; //
|
| 39 |
```
|
| 40 |
|
| 41 |
``` cpp
|
| 42 |
class L { public: int next; ... };
|
| 43 |
class A : public L { ... };
|
|
@@ -50,38 +50,38 @@ class D : public A, public L { void f(); ... }; // well-formed
|
|
| 50 |
|
| 51 |
A base class specifier that does not contain the keyword `virtual`
|
| 52 |
specifies a *non-virtual base class*. A base class specifier that
|
| 53 |
contains the keyword `virtual` specifies a *virtual base class*. For
|
| 54 |
each distinct occurrence of a non-virtual base class in the class
|
| 55 |
-
lattice of the most derived class, the most derived object
|
| 56 |
-
[[intro.object]]
|
| 57 |
subobject of that type. For each distinct base class that is specified
|
| 58 |
virtual, the most derived object shall contain a single base class
|
| 59 |
subobject of that type.
|
| 60 |
|
| 61 |
[*Note 4*:
|
| 62 |
|
| 63 |
For an object of class type `C`, each distinct occurrence of a
|
| 64 |
(non-virtual) base class `L` in the class lattice of `C` corresponds
|
| 65 |
one-to-one with a distinct `L` subobject within the object of type `C`.
|
| 66 |
Given the class `C` defined above, an object of class `C` will have two
|
| 67 |
-
subobjects of class `L` as shown in Figure
|
| 68 |
|
| 69 |
-
<a id="fig:nonvirt"></a>
|
| 70 |
|
| 71 |
-
![Non-virtual base \[fig:nonvirt\]](images/fignonvirt.svg)
|
| 72 |
|
| 73 |
In such lattices, explicit qualification can be used to specify which
|
| 74 |
subobject is meant. The body of function `C::f` could refer to the
|
| 75 |
member `next` of each `L` subobject:
|
| 76 |
|
| 77 |
``` cpp
|
| 78 |
void C::f() { A::next = B::next; } // well-formed
|
| 79 |
```
|
| 80 |
|
| 81 |
Without the `A::` or `B::` qualifiers, the definition of `C::f` above
|
| 82 |
-
would be ill-formed because of ambiguity
|
| 83 |
|
| 84 |
— *end note*]
|
| 85 |
|
| 86 |
[*Note 5*:
|
| 87 |
|
|
@@ -92,19 +92,19 @@ class V { ... };
|
|
| 92 |
class A : virtual public V { ... };
|
| 93 |
class B : virtual public V { ... };
|
| 94 |
class C : public A, public B { ... };
|
| 95 |
```
|
| 96 |
|
| 97 |
-
<a id="fig:virt"></a>
|
| 98 |
|
| 99 |
-
![Virtual base \[fig:virt\]](images/figvirt.svg)
|
| 100 |
|
| 101 |
For an object `c` of class type `C`, a single subobject of type `V` is
|
| 102 |
shared by every base class subobject of `c` that has a `virtual` base
|
| 103 |
class of type `V`. Given the class `C` defined above, an object of class
|
| 104 |
-
`C` will have one subobject of class `V`, as shown in Figure
|
| 105 |
-
[[fig:virt]].
|
| 106 |
|
| 107 |
— *end note*]
|
| 108 |
|
| 109 |
[*Note 6*:
|
| 110 |
|
|
@@ -123,14 +123,14 @@ For an object of class `AA`, all `virtual` occurrences of base class `B`
|
|
| 123 |
in the class lattice of `AA` correspond to a single `B` subobject within
|
| 124 |
the object of type `AA`, and every other occurrence of a (non-virtual)
|
| 125 |
base class `B` in the class lattice of `AA` corresponds one-to-one with
|
| 126 |
a distinct `B` subobject within the object of type `AA`. Given the class
|
| 127 |
`AA` defined above, class `AA` has two subobjects of class `B`: `Z`’s
|
| 128 |
-
`B` and the virtual `B` shared by `X` and `Y`, as shown in Figure
|
| 129 |
-
[[fig:virtnonvirt]].
|
| 130 |
|
| 131 |
-
<a id="fig:virtnonvirt"></a>
|
| 132 |
|
| 133 |
-
![Virtual and non-virtual base \[fig:virtnonvirt\]](images/figvirtnonvirt.svg)
|
| 134 |
|
| 135 |
— *end note*]
|
| 136 |
|
|
|
|
| 1 |
+
### Multiple base classes <a id="class.mi">[[class.mi]]</a>
|
| 2 |
|
| 3 |
A class can be derived from any number of base classes.
|
| 4 |
|
| 5 |
[*Note 1*: The use of more than one direct base class is often called
|
| 6 |
multiple inheritance. — *end note*]
|
|
|
|
| 15 |
```
|
| 16 |
|
| 17 |
— *end example*]
|
| 18 |
|
| 19 |
[*Note 2*: The order of derivation is not significant except as
|
| 20 |
+
specified by the semantics of initialization by constructor
|
| 21 |
+
[[class.base.init]], cleanup [[class.dtor]], and storage layout (
|
| 22 |
+
[[class.mem]], [[class.access.spec]]). — *end note*]
|
| 23 |
|
| 24 |
A class shall not be specified as a direct base class of a derived class
|
| 25 |
more than once.
|
| 26 |
|
| 27 |
[*Note 3*: A class can be an indirect base class more than once and can
|
|
|
|
| 33 |
|
| 34 |
[*Example 2*:
|
| 35 |
|
| 36 |
``` cpp
|
| 37 |
class X { ... };
|
| 38 |
+
class Y : public X, public X { ... }; // error
|
| 39 |
```
|
| 40 |
|
| 41 |
``` cpp
|
| 42 |
class L { public: int next; ... };
|
| 43 |
class A : public L { ... };
|
|
|
|
| 50 |
|
| 51 |
A base class specifier that does not contain the keyword `virtual`
|
| 52 |
specifies a *non-virtual base class*. A base class specifier that
|
| 53 |
contains the keyword `virtual` specifies a *virtual base class*. For
|
| 54 |
each distinct occurrence of a non-virtual base class in the class
|
| 55 |
+
lattice of the most derived class, the most derived object
|
| 56 |
+
[[intro.object]] shall contain a corresponding distinct base class
|
| 57 |
subobject of that type. For each distinct base class that is specified
|
| 58 |
virtual, the most derived object shall contain a single base class
|
| 59 |
subobject of that type.
|
| 60 |
|
| 61 |
[*Note 4*:
|
| 62 |
|
| 63 |
For an object of class type `C`, each distinct occurrence of a
|
| 64 |
(non-virtual) base class `L` in the class lattice of `C` corresponds
|
| 65 |
one-to-one with a distinct `L` subobject within the object of type `C`.
|
| 66 |
Given the class `C` defined above, an object of class `C` will have two
|
| 67 |
+
subobjects of class `L` as shown in Figure [[fig:class.nonvirt]].
|
| 68 |
|
| 69 |
+
<a id="fig:class.nonvirt"></a>
|
| 70 |
|
| 71 |
+
![Non-virtual base \[fig:class.nonvirt\]](images/fignonvirt.svg)
|
| 72 |
|
| 73 |
In such lattices, explicit qualification can be used to specify which
|
| 74 |
subobject is meant. The body of function `C::f` could refer to the
|
| 75 |
member `next` of each `L` subobject:
|
| 76 |
|
| 77 |
``` cpp
|
| 78 |
void C::f() { A::next = B::next; } // well-formed
|
| 79 |
```
|
| 80 |
|
| 81 |
Without the `A::` or `B::` qualifiers, the definition of `C::f` above
|
| 82 |
+
would be ill-formed because of ambiguity [[class.member.lookup]].
|
| 83 |
|
| 84 |
— *end note*]
|
| 85 |
|
| 86 |
[*Note 5*:
|
| 87 |
|
|
|
|
| 92 |
class A : virtual public V { ... };
|
| 93 |
class B : virtual public V { ... };
|
| 94 |
class C : public A, public B { ... };
|
| 95 |
```
|
| 96 |
|
| 97 |
+
<a id="fig:class.virt"></a>
|
| 98 |
|
| 99 |
+
![Virtual base \[fig:class.virt\]](images/figvirt.svg)
|
| 100 |
|
| 101 |
For an object `c` of class type `C`, a single subobject of type `V` is
|
| 102 |
shared by every base class subobject of `c` that has a `virtual` base
|
| 103 |
class of type `V`. Given the class `C` defined above, an object of class
|
| 104 |
+
`C` will have one subobject of class `V`, as shown in Figure
|
| 105 |
+
[[fig:class.virt]].
|
| 106 |
|
| 107 |
— *end note*]
|
| 108 |
|
| 109 |
[*Note 6*:
|
| 110 |
|
|
|
|
| 123 |
in the class lattice of `AA` correspond to a single `B` subobject within
|
| 124 |
the object of type `AA`, and every other occurrence of a (non-virtual)
|
| 125 |
base class `B` in the class lattice of `AA` corresponds one-to-one with
|
| 126 |
a distinct `B` subobject within the object of type `AA`. Given the class
|
| 127 |
`AA` defined above, class `AA` has two subobjects of class `B`: `Z`’s
|
| 128 |
+
`B` and the virtual `B` shared by `X` and `Y`, as shown in Figure
|
| 129 |
+
[[fig:class.virtnonvirt]].
|
| 130 |
|
| 131 |
+
<a id="fig:class.virtnonvirt"></a>
|
| 132 |
|
| 133 |
+
![Virtual and non-virtual base \[fig:class.virtnonvirt\]](images/figvirtnonvirt.svg)
|
| 134 |
|
| 135 |
— *end note*]
|
| 136 |
|