File: declaring.yo

package info (click to toggle)
c%2B%2B-annotations 12.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,044 kB
  • sloc: cpp: 24,337; makefile: 1,517; ansic: 165; sh: 121; perl: 90
file content (29 lines) | stat: -rw-r--r-- 1,236 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Nested classes hi(nested class: declaration) may be declared before they are
actually defined in a surrounding class. Such forward declarations are
required if a class contains multiple nested classes, and the nested classes
contain pointers, references, parameters or return values to objects of the
other nested classes.

For example, the following class tt(Outer) contains two nested classes
tt(Inner1) and tt(Inner2). The class tt(Inner1) contains a pointer to
tt(Inner2) objects, and tt(Inner2) contains a pointer to tt(Inner1)
objects. Cross references require forward declarations. Forward declarations
must be given an access specification that is identical to the access
specification of their definitions. In the following example the tt(Inner2)
forward declaration must be given in a tt(private) section, as its definition
is also part of the class tt(Outer)'s private interface:
        verb(    class Outer
    {
        private:
            class Inner2;       // forward declaration

            class Inner1
            {
                Inner2 *pi2;    // points to Inner2 objects
            };
            class Inner2
            {
                Inner1 *pi1;    // points to Inner1 objects
            };
    };)