Topic: using declaration and class scope


Author: wmm@fastdial.net
Date: 1999/07/26
Raw View
In article <37984E0B.2BDD189E@sea.ericsson.se>,
  Gerhard Menzl <gerhard.menzl@sea.ericsson.se> wrote:
>
> A using-declaration for a class member must be a member-declaration
> (7.3.3/6). I take this to mean that one cannot introduce the name of a
> member variable or member function of a class into a scope other than
> that of a derived class. But what about typedefs in class scope?
> Typedefs, at least in my understanding, are not members

According to 9.2p1, "Members of a class are... nested types...
Nested types are classes (9.1.9.7) and enumerations (7.2) defined
in the class, and arbitrary types declared as members by use of a
typedef declaration (7.1.3)."  That sounds like they're members
to me.

--
William M. Miller, wmm@fastdial.net
Software Emancipation Technology (www.setech.com)


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "G.B." <gb@home.nospam.net>
Date: 1999/07/26
Raw View
Gerhard Menzl <gerhard.menzl@sea.ericsson.se> wrote in message
news:37984E0B.2BDD189E@sea.ericsson.se...
>
> A using-declaration for a class member must be a member-declaration
> (7.3.3/6). I take this to mean that one cannot introduce the name of a
> member variable or member function of a class into a scope other than
> that of a derived class. But what about typedefs in class scope?
> Typedefs, at least in my understanding, are not members. Is the
> following well-formed?

Typedefs introduced in a class are members of the class. See 9.2p1, that
says that member-specification can be a typedef declaration. Since
using-declaration must be a member-declaration, you cannot introduce it in a
function scope. Though I found the code you presented does compile with some
compilers I believe it is an error and it shouldn't compile.

Gene.



[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Gerhard Menzl <gerhard.menzl@sea.ericsson.se>
Date: 1999/07/23
Raw View
A using-declaration for a class member must be a member-declaration
(7.3.3/6). I take this to mean that one cannot introduce the name of a
member variable or member function of a class into a scope other than
that of a derived class. But what about typedefs in class scope?
Typedefs, at least in my understanding, are not members. Is the
following well-formed?

   struct A
   {
      typedef unsigned char byte;
   };

   void f ()
   {
      using A::byte;      // legal?
      byte b = '\0';
   }

One of my compilers accepts it, the other one complains, somewhat
whimsically, that a "namespace declaration can occur only in global
scope or namespace scope".

Gerhard Menzl


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]