tmp/tmpr97rooed/{from.md → to.md}
RENAMED
|
@@ -2,10 +2,12 @@
|
|
| 2 |
|
| 3 |
The access rules (Clause [[class.access]]) for a virtual function are
|
| 4 |
determined by its declaration and are not affected by the rules for a
|
| 5 |
function that later overrides it.
|
| 6 |
|
|
|
|
|
|
|
| 7 |
``` cpp
|
| 8 |
class B {
|
| 9 |
public:
|
| 10 |
virtual int f();
|
| 11 |
};
|
|
@@ -18,16 +20,17 @@ private:
|
|
| 18 |
void f() {
|
| 19 |
D d;
|
| 20 |
B* pb = &d;
|
| 21 |
D* pd = &d;
|
| 22 |
|
| 23 |
-
pb->f(); // OK: B::f() is public,
|
| 24 |
-
// D::f() is invoked
|
| 25 |
pd->f(); // error: D::f() is private
|
| 26 |
}
|
| 27 |
```
|
| 28 |
|
|
|
|
|
|
|
| 29 |
Access is checked at the call point using the type of the expression
|
| 30 |
used to denote the object for which the member function is called (`B*`
|
| 31 |
in the example above). The access of the member function in the class in
|
| 32 |
which it was defined (`D` in the example above) is in general not known.
|
| 33 |
|
|
|
|
| 2 |
|
| 3 |
The access rules (Clause [[class.access]]) for a virtual function are
|
| 4 |
determined by its declaration and are not affected by the rules for a
|
| 5 |
function that later overrides it.
|
| 6 |
|
| 7 |
+
[*Example 1*:
|
| 8 |
+
|
| 9 |
``` cpp
|
| 10 |
class B {
|
| 11 |
public:
|
| 12 |
virtual int f();
|
| 13 |
};
|
|
|
|
| 20 |
void f() {
|
| 21 |
D d;
|
| 22 |
B* pb = &d;
|
| 23 |
D* pd = &d;
|
| 24 |
|
| 25 |
+
pb->f(); // OK: B::f() is public, D::f() is invoked
|
|
|
|
| 26 |
pd->f(); // error: D::f() is private
|
| 27 |
}
|
| 28 |
```
|
| 29 |
|
| 30 |
+
— *end example*]
|
| 31 |
+
|
| 32 |
Access is checked at the call point using the type of the expression
|
| 33 |
used to denote the object for which the member function is called (`B*`
|
| 34 |
in the example above). The access of the member function in the class in
|
| 35 |
which it was defined (`D` in the example above) is in general not known.
|
| 36 |
|