Topic: nested classes in namespace scope and base-specifier-list scope


Author: spambo_steffan_lankinensucks@hotmail.com ("Bo-Staffan Lankinen")
Date: Wed, 11 Sep 2002 17:59:47 +0000 (UTC)
Raw View
> I think you found it, as a matter of fact.  Yes, the definition
> is in the namespace scope, but since 'Derived' is prefixed with
> "Outer::", the scope of 'Outer' shall be considered from that
> point on for any base class name look-up.

IMO the standard isn't clear about that, atleast not with regard to the
base-specifier list. As a matter of fact I've submitted this very issue to
my compiler vendor some time ago. They would bring it up at the next meeting
of the committee. I'll get back with the resolution.

Bo-Staffan


---
[ 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.jamesd.demon.co.uk/csc/faq.html                       ]





Author: pavel@despammed.com ("Pavel Kuznetsov")
Date: Tue, 10 Sep 2002 20:26:55 +0000 (UTC)
Raw View
Victor Bazarov (vAbazarov@dAnai.com) writes

>> I just can't find exact wording in the standard which allows
>> to omit qualification in base-specifier-list in the following
>> example:
>>
>>   class Outer
>>   {
>>   public:
>>     class Base;
>>     class Derived;
>>   };
>>
>>   class Outer::Derived : public Base // note: Base is unqualified
>>   {
>>   };

VB> I think you found it, as a matter of fact.  Yes, the definition
VB> is in the namespace scope, but since 'Derived' is prefixed with
VB> "Outer::", the scope of 'Outer' shall be considered from that
VB> point on for any base class name look-up.

<...>

VB>     class Foo
VB>     {
VB>         static int fortytwo;
VB>     public:
VB>         Foo(int);
VB>     };

VB>     int Foo::fortytwo = 42;

VB>     Foo::Foo(int a = fortytwo) // fortytwo doesn't need to be
VB>                                // qualified because we've Foo::
VB>                                // in front

<...>

VB> In the definition of the c-tor I used 'fortytwo' member without
VB> qualification.  It is OK because as soon as you pass the '::',
VB> the "default" scope is set to that of class/namespace before
VB> the '::'.

It seems that appropriate place which covers both cases is 3.3.6/1:

5) The potential scope of a declaration that extends to or past the
   end of a class definition also extends to the regions defined by
   its member definitions, even if the members are defined lexically
   outside the class (this includes static data member definitions,
   nested class definitions, member function definitions (including
   the member function body and, for constructor functions (12.1),
   the ctor-initializer (12.6.2)) and any portion of the declarator
   part of such definitions which follows the identifier, including
   a parameter-declaration-clause and any default arguments (8.3.6).

Is it?

--
Pavel

---
[ 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.jamesd.demon.co.uk/csc/faq.html                       ]





Author: pavel@despammed.com ("Pavel Kuznetsov")
Date: Mon, 9 Sep 2002 19:03:56 +0000 (UTC)
Raw View
I just can't find exact wording in the standard which allows
to omit qualification in base-specifier-list in the following
example:

  class Outer
  {
  public:
    class Base;
    class Derived;
  };

  class Outer::Derived : public Base // note: Base is unqualified
  {
  };

Standard says that "The nested class is in the scope of its
enclosing class." and in other place it is also said that
"[Note: because a baseclause for a nested class is part of the
declaration of the nested class itself (and not part of the
declarations of the members of the nested class), the base-clause
may refer to the private members of the enclosing class."

So, in our case definition of Outer::Derived is located in
namespace scope and there is no Base here and I could not find
any special lookup rules for names in base-specifier-list.

--
Pavel

---
[ 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.jamesd.demon.co.uk/csc/faq.html                       ]





Author: vAbazarov@dAnai.com ("Victor Bazarov")
Date: Mon, 9 Sep 2002 20:46:56 +0000 (UTC)
Raw View
"Pavel Kuznetsov" <pavel@despammed.com> wrote...
> I just can't find exact wording in the standard which allows
> to omit qualification in base-specifier-list in the following
> example:
>
>   class Outer
>   {
>   public:
>     class Base;
>     class Derived;
>   };
>
>   class Outer::Derived : public Base // note: Base is unqualified
>   {
>   };
>
> Standard says that "The nested class is in the scope of its
> enclosing class." and in other place it is also said that
> "[Note: because a baseclause for a nested class is part of the
> declaration of the nested class itself (and not part of the
> declarations of the members of the nested class), the base-clause
> may refer to the private members of the enclosing class."
>
> So, in our case definition of Outer::Derived is located in
> namespace scope and there is no Base here and I could not find
> any special lookup rules for names in base-specifier-list.


I think you found it, as a matter of fact.  Yes, the definition
is in the namespace scope, but since 'Derived' is prefixed with
"Outer::", the scope of 'Outer' shall be considered from that
point on for any base class name look-up.

Take a look at this:

    class Foo
    {
        static int fortytwo;
    public:
        Foo(int);
    };

    int Foo::fortytwo = 42;

    Foo::Foo(int a = fortytwo) // fortytwo doesn't need to be
                               // qualified because we've Foo::
                               // in front
    {
        // do smth with 'a'
    }

In the definition of the c-tor I used 'fortytwo' member without
qualification.  It is OK because as soon as you pass the '::',
the "default" scope is set to that of class/namespace before
the '::'.

HTH

Victor
--
Please remove capital A's from my address when replying by mail


---
[ 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.jamesd.demon.co.uk/csc/faq.html                       ]