mirror of
https://gitlab.com/fbb-git/cppannotations
synced 2024-11-16 07:48:44 +01:00
5a94aed820
git-svn-id: https://cppannotations.svn.sourceforge.net/svnroot/cppannotations/trunk@349 f6dd340e-d3f9-0310-b409-bdd246841980
30 lines
1.2 KiB
Text
30 lines
1.2 KiB
Text
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
|
|
};
|
|
};
|
|
)
|