From Jason Turner

[class.nest]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmptdc_u39o/{from.md → to.md} +17 -27
tmp/tmptdc_u39o/{from.md → to.md} RENAMED
@@ -1,11 +1,9 @@
1
  ### Nested class declarations <a id="class.nest">[[class.nest]]</a>
2
 
3
  A class can be declared within another class. A class declared within
4
- another is called a *nested class*. The name of a nested class is local
5
- to its enclosing class. The nested class is in the scope of its
6
- enclosing class.
7
 
8
  [*Note 1*: See  [[expr.prim.id]] for restrictions on the use of
9
  non-static data members and non-static member functions. — *end note*]
10
 
11
  [*Example 1*:
@@ -18,29 +16,33 @@ struct enclose {
18
  int x;
19
  static int s;
20
 
21
  struct inner {
22
  void f(int i) {
23
- int a = sizeof(x); // OK: operand of sizeof is an unevaluated operand
24
  x = i; // error: assign to enclose::x
25
- s = i; // OK: assign to enclose::s
26
- ::x = i; // OK: assign to global x
27
- y = i; // OK: assign to global y
28
  }
29
  void g(enclose* p, int i) {
30
- p->x = i; // OK: assign to enclose::x
31
  }
32
  };
33
  };
34
 
35
- inner* p = 0; // error: inner not in scope
36
  ```
37
 
38
  — *end example*]
39
 
40
- Member functions and static data members of a nested class can be
41
- defined in a namespace scope enclosing the definition of their class.
 
 
 
 
42
 
43
  [*Example 2*:
44
 
45
  ``` cpp
46
  struct enclose {
@@ -51,33 +53,21 @@ struct enclose {
51
  };
52
 
53
  int enclose::inner::x = 1;
54
 
55
  void enclose::inner::f(int i) { ... }
56
- ```
57
 
58
- — *end example*]
59
-
60
- If class `X` is defined in a namespace scope, a nested class `Y` may be
61
- declared in class `X` and later defined in the definition of class `X`
62
- or be later defined in a namespace scope enclosing the definition of
63
- class `X`.
64
-
65
- [*Example 3*:
66
-
67
- ``` cpp
68
  class E {
69
  class I1; // forward declaration of nested class
70
  class I2;
71
  class I1 { }; // definition of nested class
72
  };
73
  class E::I2 { }; // definition of nested class
74
  ```
75
 
76
  — *end example*]
77
 
78
- Like a member function, a friend function [[class.friend]] defined
79
- within a nested class is in the lexical scope of that class; it obeys
80
- the same rules for name binding as a static member function of that
81
- class [[class.static]], but it has no special access rights to members
82
- of an enclosing class.
83
 
 
1
  ### Nested class declarations <a id="class.nest">[[class.nest]]</a>
2
 
3
  A class can be declared within another class. A class declared within
4
+ another is called a *nested class*.
 
 
5
 
6
  [*Note 1*: See  [[expr.prim.id]] for restrictions on the use of
7
  non-static data members and non-static member functions. — *end note*]
8
 
9
  [*Example 1*:
 
16
  int x;
17
  static int s;
18
 
19
  struct inner {
20
  void f(int i) {
21
+ int a = sizeof(x); // OK, operand of sizeof is an unevaluated operand
22
  x = i; // error: assign to enclose::x
23
+ s = i; // OK, assign to enclose::s
24
+ ::x = i; // OK, assign to global x
25
+ y = i; // OK, assign to global y
26
  }
27
  void g(enclose* p, int i) {
28
+ p->x = i; // OK, assign to enclose::x
29
  }
30
  };
31
  };
32
 
33
+ inner* p = 0; // error: inner not found
34
  ```
35
 
36
  — *end example*]
37
 
38
+ [*Note 2*:
39
+
40
+ Nested classes can be defined either in the enclosing class or in an
41
+ enclosing namespace; member functions and static data members of a
42
+ nested class can be defined either in the nested class or in an
43
+ enclosing namespace scope.
44
 
45
  [*Example 2*:
46
 
47
  ``` cpp
48
  struct enclose {
 
53
  };
54
 
55
  int enclose::inner::x = 1;
56
 
57
  void enclose::inner::f(int i) { ... }
 
58
 
 
 
 
 
 
 
 
 
 
 
59
  class E {
60
  class I1; // forward declaration of nested class
61
  class I2;
62
  class I1 { }; // definition of nested class
63
  };
64
  class E::I2 { }; // definition of nested class
65
  ```
66
 
67
  — *end example*]
68
 
69
+ *end note*]
70
+
71
+ A friend function [[class.friend]] defined within a nested class has no
72
+ special access rights to members of an enclosing class.
 
73