You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a06d3f8
Browse filesBrowse the repository at this point in the historyBrowse files
The conceptual memory layout of an object of type `Date` is shown in the following figure.
37
36
38
-
 <br/>
39
-
Memory Layout of Date Object
37
+
:::image type="complex" source="../cpp/media/vc38uq1.png" alt-text="Memory layout of a date object, showing where the nWeekDay, nMonthDay, nMonth, and nYear bit fields fall.":::
38
+
32 bits of memory are displayed in a row. The rightmost 3 bits are for nWeekDay. The next 6 bits to the left are for nMonthDay. The next 5 bits to the left are for nMonth. The next two bits are unused. The next 8 bits are for nYear. The remaining 8 bits to the left are unused.
39
+
:::image-end:::
40
40
41
41
Note that `nYear` is 8 bits long and would overflow the word boundary of the declared type, **`unsigned short`**. Therefore, it is begun at the beginning of a new **`unsigned short`**. It is not necessary that all bit fields fit in one object of the underlying type; new units of storage are allocated, according to the number of bits requested in the declaration.
42
42
@@ -62,8 +62,9 @@ struct Date {
62
62
63
63
then the memory layout is as shown in the following figure:
64
64
65
-
 <br/>
66
-
Layout of Date Object with Zero-Length Bit Field
65
+
:::image type="complex" source="../cpp/media/vc38uq2.png" alt-text="Layout of a Date object with a zero length bit field, which forces alignment padding.":::
66
+
64 bits of memory are displayed in a row. The rightmost 5 bits are for nMonth. The next 8 bits to the left are for nYear. The next 19 bits to the left are unused. The next 3 bits to the left are for nWeekDay. The next 6 bits to the left are for nMonthDay. The remaining bits to the left are unused.
67
+
:::image-end:::
67
68
68
69
The underlying type of a bit field must be an integral type, as described in [Built-in types](../cpp/fundamental-types-cpp.md).
 <br/>
118
-
Class hierarchy that shows multiple inheritance
116
+
:::image type="complex" source="../cpp/media/vc39011.gif" alt-text="Class hierarchy that shows multiple inheritance.":::
117
+
The diagram shows a class hierarchy with A as a base class of B which in turn is a base class of D. A is also a base class for C which in turn is a base class for D. Note that class D inherits from both B and C.
118
+
:::image-end:::
119
119
120
120
A pointer to an object of type `D` can be safely cast to `B` or `C`. However, if `D` is cast to point to an `A` object, which instance of `A` would result? This would result in an ambiguous casting error. To get around this problem, you can perform two unambiguous casts. For example:
121
121
@@ -137,14 +137,18 @@ void f() {
137
137
138
138
Further ambiguities can be introduced when you use virtual base classes. Consider the class hierarchy shown in the following figure.
139
139
140
-
 <br/>
140
+
:::image type="complex" source="../cpp/media/vc39012.gif" alt-text="Class hierarchy that shows virtual base classes.":::
141
+
The diagram shows the classes A, B, C, D, and E arranged as follows: Class A is a base class of B. Classes C and E each derive from B. Class E also inherits from D which inherits from class B which in turn inherits from class A.
142
+
:::image-end:::
141
143
Class hierarchy that shows virtual base classes
142
144
143
145
In this hierarchy, `A` is a virtual base class. Given an instance of class `E` and a pointer to the `A` subobject, a **`dynamic_cast`** to a pointer to `B` will fail due to ambiguity. You must first cast back to the complete `E` object, then work your way back up the hierarchy, in an unambiguous manner, to reach the correct `B` object.
144
146
145
147
Consider the class hierarchy shown in the following figure.
146
148
147
-
 <br/>
149
+
:::image type="complex" source="../cpp/media/vc39013.gif" alt-text="Class hierarchy that shows duplicate base classes.":::
150
+
The diagram shows the classes A, B, C, D, and E arranged as follows: Class B derives from Class A. Class C derives from class A. class D derives from class B. Class E derives from class C which derives from class A. In this case, the duplicate base class is class A which is directly or indirectly inherited by all the other classes. Class A is inherited directly by classes B and C, and indirectly by class D via class B, and indirectly by class E via class C, and indirectly in class D via class B.
151
+
:::image-end:::
148
152
Class hierarchy that shows duplicate base classes
149
153
150
154
Given an object of type `E` and a pointer to the `D` subobject, to navigate from the `D` subobject to the left-most `A` subobject, three conversions can be made. You can perform a **`dynamic_cast`** conversion from the `D` pointer to an `E` pointer, then a conversion (either **`dynamic_cast`** or an implicit conversion) from `E` to `B`, and finally an implicit conversion from `B` to `A`. For example:
@@ -225,8 +224,9 @@ Friendship isn't inherited, meaning that classes derived from `YourOtherClass` c
225
224
226
225
The following figure shows four class declarations: `Base`, `Derived`, `aFriend`, and `anotherFriend`. Only class `aFriend` has direct access to the private members of `Base` (and to any members `Base` might have inherited).
227
226
228
-
 <br/>
229
-
Implications of friend relationship
227
+
::image type="complex" source="../cpp/media/vc38v41.gif" alt-text="Diagram showing the derivation implications of a friend relationship.":::
228
+
The diagram shows that class anotherFriend doesn't have a friend relationship with class base which friends class aFriend. Class aFriend is friended by class Base, but it doesn't have a friend relationship with class Derived even though class Derived inherits from Base, thus showing that inheritance doesn't imply the derived class has the same friends as the base class.
@@ -19,7 +18,10 @@ The C++17 standard defines expression value categories as follows:
19
18
20
19
The following diagram illustrates the relationships between the categories:
21
20
22
-

21
+
:::image type="complex" source="media/value_categories.png" alt-text="C++ expression value categories.":::
22
+
The diagram begins with a box labeled expression, which has two children: glvalue and rvalue. glvalue has two children: lvalue and xvalue. rvalue has two children: prvalue, and it shares xvalue which is also a child of glvalue.
23
+
:::image-end:::
24
+
23
25
24
26
An lvalue has an address that your program can access. Examples of lvalue expressions include variable names, including **`const`** variables, array elements, function calls that return an lvalue reference, bit-fields, unions, and class members.
Copy file name to clipboardExpand all lines: docs/cpp/member-access-control-cpp.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -230,7 +230,9 @@ In the preceding example, calling the virtual function `GetState` using a pointe
230
230
231
231
In multiple-inheritance lattices involving virtual base classes, a given name can be reached through more than one path. Because different access control can be applied along these different paths, the compiler chooses the path that gives the most access. See the following figure.
232
232
233
-
 <br/>
233
+
:::image type="complex" source="../cpp/media/vc38v91.gif" alt-text="Diagram showing access along the paths of an inheritance graph.":::
234
+
The diagram shows the following inheritance hierarchy: class VBase is the base class. Class LeftPath inherits from VBase using virtual private VBase. class RightPath also inherits from VBase but using virtual public VBase. Finally, class Derived inherits from both class LeftPath and class RightPath using public LeftPath, public RightPath.
235
+
:::image-end:::
234
236
Access along paths of an inheritance graph
235
237
236
238
In the figure, a name declared in class `VBase` is always reached through class `RightPath`. The right path is more accessible because `RightPath` declares `VBase` as a **`public`** base class, while `LeftPath` declares `VBase` as **`private`**.
The `NumericType` union is arranged in memory (conceptually) as shown in the following figure.
538
537
539
-
 <br/>
540
-
Storage of data in a `NumericType` union
538
+
:::image type="complex" source="../cpp/media/vc38ul1.png" alt-text="Diagram that shows the overlapping storage of data in the NumericType union.":::
539
+
The diagram shows 8 bytes of data. The type double dValue occupies the entire 8 bytes. The type long lValue occupies the first four bytes. The type short iValue occupies the first byte.
0 commit comments