Topic: One last question about const & initializers


Author: comeau@panix.com (Greg Comeau)
Date: 2000/10/10
Raw View
In article <39e1b089.16630827@news.nikoma.de>,
Martin Aupperle <MikeAlpha@NoSpam_csi.com> wrote:
>In 8.5.1, the standard says what an aggregate is and how it can be
>initialized.
>
>>From that, I conclude that
>
> struct S {  const int i;  }
>
>is an aggregate

This is wrong, because i needs to be member initialized, so...

>and it should be possible to initialize an object of S
>like
>
> S s = { 1 };

This is not possible.

>But I receive an error message. The compiler wants S to have a user
>defined constructor. I can understand that, but is this backed by the
>Standard?

References and const members must be member initialized.

>One compiler (BCB4) complains when compiling the definition of S,
>another (VC6) complains when trying to make an object.
>
>Same for reference members.

Yup.  Should be covered in some 8.5 or 12.6 section.

- Greg
--
Comeau Computing / Comeau C/C++ "so close" 4.2.44 betas NOW AVAILABLE
TRY Comeau C++ ONLINE at http://www.comeaucomputing.com/tryitout
Email: comeau@comeaucomputing.com / WEB: http://www.comeaucomputing.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                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: wmm@fastdial.net
Date: 2000/10/10
Raw View
In article <39e1b089.16630827@news.nikoma.de>,
  MikeAlpha@NoSpam_csi.com (Martin Aupperle) wrote:
> Hello,
>
> In 8.5.1, the standard says what an aggregate is and how it can be
> initialized.
>
> >From that, I conclude that
>
>  struct S {  const int i;  }
>
> is an aggregate and it should be possible to initialize an object of S
> like
>
>  S s = { 1 };
>
> But I receive an error message. The compiler wants S to have a user
> defined constructor. I can understand that, but is this backed by the
> Standard?
>
> One compiler (BCB4) complains when compiling the definition of S,
> another (VC6) complains when trying to make an object.
>
> Same for reference members.

The compilers are in error.  This is an aggregate and can be
initialized this way.  Same for reference members.

--
William M. Miller, wmm@fastdial.net
Vignette Corporation (www.vignette.com)


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ 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: MikeAlpha@NoSpam_csi.com (Martin Aupperle)
Date: 2000/10/09
Raw View
Hello,

In 8.5.1, the standard says what an aggregate is and how it can be
initialized.

>From that, I conclude that

 struct S {  const int i;  }

is an aggregate and it should be possible to initialize an object of S
like

 S s = { 1 };

But I receive an error message. The compiler wants S to have a user
defined constructor. I can understand that, but is this backed by the
Standard?

One compiler (BCB4) complains when compiling the definition of S,
another (VC6) complains when trying to make an object.

Same for reference members.

Martin



------------------------------------------------
Martin Aupperle
MikeAlpha@NoSpam_csi.com
(remove NoSpam_)
------------------------------------------------

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