Topic: where is the logic ?
Author: Stephen Clamage <stephen.clamage@sun.com>
Date: Wed, 11 Jul 2001 17:00:24 GMT Raw View
On Sun, 8 Jul 2001 23:07:35 GMT, "Bartok" <odin@worldnet.fr> wrote:
>
>struct a;
>struct a::b;
>a *val1;
>a::b *val2;
>
>failed at compile time since it needs an explicit
>include to have the full prototype of struct a.
>But why ?
You are not allowed to mention a member of a struct unless the (one
and only) struct definition has been seen. The main reason is to
disallow the possibility of changing the compiler's notion of the
struct definition without modifying that definition. It also
eliminates the problem of having the class definition spread across
different files which then would have to be kept synchronized.
---
Steve Clamage, stephen.clamage@sun.com
---
[ 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: "Bartok" <odin@worldnet.fr>
Date: Sun, 8 Jul 2001 23:07:35 GMT Raw View
Giving the following code :
struct a;
struct b;
a *val1;
b *val2;
works at compile time.
Now if b is inside a :
struct a;
struct a::b;
a *val1;
a::b *val2;
failed at compile time since it needs an explicit
include to have the full prototype of struct a.
But why ? It's not very logical. It could look for
struct a::b at link time as it would make for struct b...
In other words, it would mean that using nested struct/class
would be more heavy at compile time because we need
to explicitly mention the include of its prototype even
if we only refer to it via a pointer.
--
Bartok.
---
[ 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 ]