From -9027960268497537334
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,2aed2eaedf310bad
X-Google-Attributes: gidf78e5,public
From: Michiel Salters <salters@lucent.com>
Subject: Re: stl list with VC++5
Date: 1999/12/01
Message-ID: <3844EF35.F02623CC@lucent.com>#1/1
X-Deja-AN: 555231841
Content-Transfer-Encoding: 7bit
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <3840B365.646F5247@insa-lyon.fr>
X-Original-Date: Wed, 01 Dec 1999 10:49:41 +0100
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: ariel.ucs.unimelb.edu.au 944042716 28238 128.250.37.153 (1 Dec 1999 10:05:16 GMT)
Organization: Lucent Technologies, Hilversum
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAOETy5OEDnX0m9pzZAQEqwAF/dlq30+NFUec0+OQQBw6iSMCC+1tCdAMx BtEKtFjZy0VWIjtyIwiXdHleKlqmdOmH =RDCG
Mime-Version: 1.0
NNTP-Posting-Date: 1 Dec 1999 10:05:16 GMT
Newsgroups: comp.std.c++

Gilles ROUX wrote:
> 
> Hi,
> The following code compiles perfectly with gcc, but not with VC++5 (see
> error message).
> Have I made a silly mistake, or is vc++ wrong (once more). Is it going
> to work if I use vc++6 ?
> If not, how can I solve this problem ?
> Thanks.
> Gilles.
 
> --------------------------------------
> #include <list>

> class A
> {
> public:
>   A();
>   std::list<A>::iterator a;
> };

> void main()
> {
> }
> ----------------------------------------
> d:\Prog\DevStudio\VC\INCLUDE\list(24) : error C2079: '_Value' uses
> undefined class 'A'
> d:\Prog\DevStudio\VC\INCLUDE\functional(180) : error C2079: 'value' uses
> undefined class 'A'
> d:\Prog\DevStudio\VC\INCLUDE\list(173) : error C2440: 'default argument'
> : cannot convert from 'class A' to 'class A'
>                                                       Source or target
> has incomplete type
> ---

You made a silly mistake - but that's void main().

The not so silly mistake that (probably :-) causes the compiler
trip-up is the use of std::list<A> inside class A. What if e.g.
the size of std::list<A> depends on the size of A? Not unreasonable,
but in that case you can't put an std::list<A> inside an A.

The basic rule is that you can't use class A as a template parameter
(to std::list, that is) until after the final '}' of its definition.
It isn't complete yet; hence the last warning. Using A* is of course
possible (its size does not depend on the sizeof(A) ). This might give
you the intended behavior. I'm wondering why an A object has to hold
an iterator to the list, though. In one way, that makes class A like
a linked list node, which is quite confusing, since it is (presumably)
on another (std::)list, too.

On the compiler comparison.
gcc is as right as vc++; this behavior is undefined behavior. Accepting
it without diagnostic is fine; refusing it is fine too. The only thing
not fine is using A as you did.

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



