Topic: Nested classes under GCC 2.95.2 and VC++ 6


Author: Roger.L.S.Griffiths@news2-win.server.ntlworld.com,
Date: Sun, 25 Mar 2001 15:05:09 GMT
Raw View
Michiel Salters wrote:

> In article <86wva5r3s7.fsf@alex.gabi-soft.de>, James Kanze says...
>>
>>Kees de Bruin <kees_de_bruin@tasking.com> writes:
>>
>>|>  I have a question related to the use of nested classes. Consider th=
e
>>|>  following example:
>>
>>|>          class SA {
>>|>                  class LST {
>>|>                          LST* _parent;
>>|> =20
>>|>   (*)                    SA::LST* getParent();
>>|>                  };
>>|>          };
>>
>>|>          SA::LST* SA::LST::getParent() { return _parent; }
>>
>>|>  When using GCC 2.95.2 I can compile the above code, but when using
>>|>  VC++ 6 I get an error on the line with (*) saying that SA is not ye=
t
>>|>  defined. So my question is, which compiler is correct, or are both
>>|>  at fault.

As I understand it the line you point out can be easily fixed:-

        class SA {
                class LST {
                        LST* _parent;

                        LST* getParent();
                };
        };

        SA::LIST* SA::LST::getParent() { return _parent; }

I believe this ought to work ... if it doesn't I'd be surprised

TTFN

Roger
--=20
Roger L.S. Griffiths, BSc (Hons)

G=F6tt Wurfelt Nicht (God does not play dice)
- Albert Einstein

---
[ 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                ]





Author: Michiel Salters<Michiel.Salters@cmg.nl>
Date: Fri, 16 Mar 2001 18:12:56 GMT
Raw View
In article <86wva5r3s7.fsf@alex.gabi-soft.de>, James Kanze says...
>
>Kees de Bruin <kees_de_bruin@tasking.com> writes:
>
>|>  I have a question related to the use of nested classes. Consider the
>|>  following example:
>
>|>          class SA {
>|>                  class LST {
>|>                          LST* _parent;
>|>
>|>   (*)                    SA::LST* getParent();
>|>                  };
>|>          };
>
>|>          SA::LST* SA::LST::getParent() { return _parent; }
>
>|>  When using GCC 2.95.2 I can compile the above code, but when using
>|>  VC++ 6 I get an error on the line with (*) saying that SA is not yet
>|>  defined. So my question is, which compiler is correct, or are both
>|>  at fault.
>
>Well, VC++ is certainly correct in saying that SA is not yet defined.
>The question is, however, who cares?  The context doesn't require that
>SA be defined. So the compiler is not required to emit the message (g++
>is thus correct), and it is not allowed to not generate the code, or in
>any other way treat the message as if it were a diagnostic in the sense
>of the standard.

James, do you mean with "the context" the context of using a pointer to
a possibly incomplete type in a member function declaration ?

I am surprised if that's possible, because in that context name1::name2
is ambiguous: name1 could be either a namespace or a class, and we know
nothing of name2 as a consequence.

Regards,
Michiel Salters

---
[ 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                ]





Author: Kees de Bruin <kees_de_bruin@tasking.com>
Date: Wed, 28 Feb 2001 19:19:50 GMT
Raw View
Hi,

I have a question related to the use of nested classes. Consider the
following example:

        class SA {
                class LST {
                        LST* _parent;

 (*)                    SA::LST* getParent();
                };
        };

        SA::LST* SA::LST::getParent() { return _parent; }

When using GCC 2.95.2 I can compile the above code, but when using VC++ 6 I
get an error on the line with (*) saying that SA is not yet defined. So my
question is, which compiler is correct, or are both at fault.

I know it is possible to simply inline the code in the nested class, but
the code is generated by Rational Rose, so somewhat restricted in what is
possible.

Kind regards,

--
Kees de Bruin                                             Software Engineer
---------------------------------------------------------------------------
E-mail:  kees_de_bruin@tasking.com                      TASKING Software BV
Voice:   +31-33-455 85 84                               Plotterweg 31
Fax:     +31-33-455 00 03                               3821 BB  Amersfoort
WWW:     http://www.tasking.com                         The Netherlands
----------------[ I like feminists - I think they're cute ]----------------

---
[ 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: "Andrei Iltchenko" <iltchenko@yahoo.com>
Date: Wed, 28 Feb 2001 22:04:12 GMT
Raw View
> Hi,
>
> I have a question related to the use of nested classes. Consider the
> following example:
>
>         class SA {
>                 class LST {
>                         LST* _parent;
>
>  (*)                    SA::LST* getParent();
>                 };
>         };
>
>         SA::LST* SA::LST::getParent() { return _parent; }
>
> When using GCC 2.95.2 I can compile the above code, but when using VC++ 6
I
> get an error on the line with (*) saying that SA is not yet defined. So my
> question is, which compiler is correct, or are both at fault.

VC++ 6 is not correct saying that "SA is not yet defined", for "A class
member can be referred to using a qualified-id at any point in its potential
scope." (3.4.3.1/1). Still, the piece of code presented is ill-formed
according to the current version of the Standard, because "members of a
nested class have no special access to the members of an enclosing class."
(11.8).

In the member-declaration
>                      SA::LST* getParent();
you explicitly refer to a private member of an enclosing class, whereas the
nested class LST has no access to the enclosing class's private members.

On the other hand the declaration
>                         LST* _parent;
is fine, since the name of a class is implicitly inserted into the class's
scope.

The member function declaration
>         SA::LST* SA::LST::getParent() { return _parent; }
is no good either, for the same reasons as its corresponding declaration.

So, according to the current state of the Standard, the only way to fix
things up in the piece you've given is to rewrite it as follows:

class SA {
   class LST  {
      LST* _parent;
      LST* getParent()
      {   return  _parent;   }
   };
};

Note though, that there has been a defect report that raised the above
issue:
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#10

According to the proposed resolution, which now has the READY status, the
piece of code you've provided is well-formed.

Cheers,
Andrei Iltchenko.



---
[ 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: James Kanze <kanze@gabi-soft.de>
Date: Sun, 4 Mar 2001 18:25:03 GMT
Raw View
Kees de Bruin <kees_de_bruin@tasking.com> writes:

|>  I have a question related to the use of nested classes. Consider the
|>  following example:

|>          class SA {
|>                  class LST {
|>                          LST* _parent;
|>
|>   (*)                    SA::LST* getParent();
|>                  };
|>          };

|>          SA::LST* SA::LST::getParent() { return _parent; }

|>  When using GCC 2.95.2 I can compile the above code, but when using
|>  VC++ 6 I get an error on the line with (*) saying that SA is not yet
|>  defined. So my question is, which compiler is correct, or are both
|>  at fault.

Well, VC++ is certainly correct in saying that SA is not yet defined.
The question is, however, who cares?  The context doesn't require that
SA be defined. So the compiler is not required to emit the message (g++
is thus correct), and it is not allowed to not generate the code, or in
any other way treat the message as if it were a diagnostic in the sense
of the standard.

--
James Kanze                               mailto:kanze@gabi-soft.de
Conseils en informatique orient   e objet/
                   Beratung in objektorientierter Datenverarbeitung
Ziegelh   ttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627

---
[ 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.     ]