Topic: Nested Class Definitions Question


Author: dsouza@optima.cad.mcc.com (Desmond Dsouza)
Date: 5 Jan 91 02:13:41 GMT
Raw View
Is it legal to forward declare a class nested in another class?
I believe the following is illegal in C++? If so, why? It is a
useful form of modularity.

class PRINTING_SYS {
  class PRINTER;      // Nested class forward declaration
  class PRINT_QUEUE;  //  "
public:
  spool();
};

class PRINTING_SYS::PRINTER { ... };
class PRINTING_SYS::PRINT_QUEUE { ... };

According to the ARM:
p. 164
"Except for historical reasons, a class declaration would have been called
a class definition"
i.e. class A {...}; is called a class declaration.

p. 185: "A class may be declared within another class"

p. 187: "Member functions and static data members of a nested class
can be defined in the global scope"

Putting these 3 together it seems that nested class (forward)
declarations are not legal.

---
Desmond.
--

-------------------------------------------------------------------------------
 Desmond D'Souza, MCC CAD Program | ARPA: dsouza@mcc.com | Phone: [512] 338-3324
 Box 200195, Austin, TX 78720 | UUCP: {uunet,harvard,gatech,pyramid}!cs.utexas.edu!milano!cadillac!dsouza