Topic: a library construction issue - forward references to nested classes
Author: derek@watson.ibm.com (Derek Lieber)
Date: Fri, 9 Apr 1993 14:34:16 GMT Raw View
When building a library using C++, it seems natural to try
to avoid polluting the namespace by hiding "internal"
classes just as one hides "internal" functions and data.
For example:
-----------------------------------------------------------
| class Thingie |
| { |
| public: |
| ...the interface... |
| |
| private: |
| ...the implementation... |
| class InternalClassA |
| { |
| class InternalClassB |
| { |
| }; |
| class InternalClassC |
| { |
| }; |
| }; |
| }; |
-----------------------------------------------------------
Now consider the standard technique for dealing with
forward references in a "flat" namespace:
-----------------------------------------------------------
| class Y; // forward reference |
| class X |
| { |
| Y *p; |
| }; |
| class Y |
| { |
| X *p; |
| }; |
-----------------------------------------------------------
How does this extend to nested classes?
One might be tempted to write:
-----------------------------------------------------------
| class X |
| { |
| class C; // forward reference |
| class C::D; // forward reference to nested class !! |
| |
| class A |
| { |
| class B |
| { |
| C::D *p; |
| }; |
| }; |
| class C |
| { |
| class D |
| { |
| A::B *p; |
| }; |
| }; |
| }; |
-----------------------------------------------------------
But current compilers (cfront, xlC, gcc) flag the line
marked with !! as illegal. For example xlC complains:
"X::C::D" must already be declared
My question is: what, if anything, does the ANSI committee
say about forward references to nested classes? Are they to
be allowed? The ARM doesn't seem to say one way or the other.
It seems to me that without such capability it is impossible to
properly manage a large namespace (ie. by decomposing it into
heirarchies of library classes in such a way as to avoid name collisions).
Comments?
--
Derek Lieber
derek@watson.ibm.com
Author: bs@alice.att.com (Bjarne Stroustrup)
Date: 10 Apr 93 16:55:39 GMT Raw View
derek@watson.ibm.com (Derek Lieber @ IBM T.J. Watson Research Center) writes
> My question is: what, if anything, does the ANSI committee
> say about forward references to nested classes? Are they to
> be allowed? The ARM doesn't seem to say one way or the other.
The ability to forward declare nested classes was approved at the
Portland meeting last month:
class X {
class C; // (forward) declaration of member class
void f(); // declaration of member function
// ...
};
class X::C { ... } // definition of member class
void X::f() { ... } // definition of member function
Implementations will appear in furture relases. Future printings
of the ARM will contain an appendix listing such resolutions.
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Sun, 11 Apr 1993 14:04:08 GMT Raw View
In article <C580H4.HIF@watson.ibm.com> derek@watson.ibm.com (Derek Lieber) writes:
>
>My question is: what, if anything, does the ANSI committee
>say about forward references to nested classes? Are they to
>be allowed?
Yes.
>It seems to me that without such capability it is impossible to
>properly manage a large namespace (ie. by decomposing it into
>heirarchies of library classes in such a way as to avoid name collisions).
>
>Comments?
>
There is a separate proposal for namespace management.
namespace X { f(); }
using namespace X;
int i=f();
namespace X { g(); }
int j=g(); // OK!
namespace Y { k(); }
int l=Y::k();
namespace {
int w; // 'static' not needed!
};
Will this help?
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd, CSERVE:10236.1703
6 MacKay St ASHFIELD, Mem: SA IT/9/22,SC22/WG21
NSW 2131, AUSTRALIA
Author: mat@mole-end.matawan.nj.us
Date: Mon, 12 Apr 1993 21:32:59 GMT Raw View
In article <25269@alice.att.com>, bs@alice.att.com (Bjarne Stroustrup) writes:
> derek@watson.ibm.com (Derek Lieber @ IBM T.J. Watson Research Center) writes
> > My question is: what, if anything, does the ANSI committee
> > say about forward references to nested classes? Are they to
> > be allowed? The ARM doesn't seem to say one way or the other.
> The ability to forward declare nested classes was approved at the
> Portland meeting last month:
>
> class X {
> class C; // (forward) declaration of member class
> void f(); // declaration of member function
> // ...
> };
>
> class X::C { ... } // definition of member class
> void X::f() { ... } // definition of member function
I believe the question was the legality of
class X;
class X::C;
I've felt a need for this from time to time too.
--
(This man's opinions are his own.)
From mole-end Mark Terribile
mat@mole-end.matawan.nj.us, Somewhere in Matawan, NJ