Topic: Can a class be declared other than with an elaborated-type-specifier?


Author: scott douglass <sdouglass@arm.com>
Date: Fri, 23 Feb 2001 11:20:47 CST
Raw View
In 3.3.1 [basic.scope.pdecl] the standards says

The point of declaration of a class first declared in an
elaborated-type-specifier is as follows:

It seems to me that the only way to (first or re-) declare a class is by using
an elaborated-type-specifier.  But the quoted bit above seems to imply that I'm
missing some other way.  Am I?

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "William M. Miller" <wmmiller@MailAndNews.com>
Date: Fri, 23 Feb 2001 12:04:55 CST
Raw View
>===== Original Message From scott douglass <sdouglass@arm.com> =====
>In 3.3.1 [basic.scope.pdecl] the standards says
>
>The point of declaration of a class first declared in an
>elaborated-type-specifier is as follows:
>
>It seems to me that the only way to (first or re-) declare a class is by
using
>an elaborated-type-specifier.  But the quoted bit above seems to imply that
I'm
>missing some other way.  Am I?

Yes.  If you look at the grammar in 7.1.5p1, you'll see that
class-specifier and enum-specifier are treated separately from
elaborated-type-specifier.  The class-specifier and enum-specifier are
the ones that actually have the definition of the type (i.e., the "{...}"
part).  An elaborated-type-specifier names the type without the
definition.

The parts of a class-specifier and enum-specifier that superficially look
like elaborated-type-specifiers (i.e., the part before the "{") really
aren't.  For instance, you can leave out the identifier that would become
the class-name or enum-name, which you can't do with an
elaborated-type-specifier, and the class-specifier has all the stuff
about base classes, which is also not permitted in an
elaborated-type-specifier.

The point of the 3.3.1 quotation is that you need not have defined a class
in order to refer to it using an elaborated-type-specifier.  For example,
you might have something like

        struct S* p;

as the very first mention of that type.  Such a declaration declares
_both_ S and p, even the definition of S (in a declaration with a
class-specifier) might occur later, or even not at all.

-- William M. Miller

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]