Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #5354
| From | Nikos Chantziaras <realnc@arcor.de> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Rationale behind user provided ctor requirement for const objects of non-POD class types |
| Date | 2011-05-23 12:07 +0300 |
| Organization | Lucas Barks |
| Message-ID | <ird841$112$1@news.grnet.gr> (permalink) |
(Originally posted to comp.std.c++, but that newsgroup is dead.)
Recently, I've seen a compiler (clang) that will not compile code like this:
struct A {
A() {}
};
class B {
A a_;
};
int foo()
{
const B b;
return 0;
}
It will not compile it because 'b' is const B, which does not have a
user defined ctor. C++'03 [dcl.init] p9 says:
If no initializer is specified for an object, and the object
is of (possibly cv-qualified) non-POD class type (or array
thereof), the object shall be default-initialized; if the
object is of const-qualified type, the underlying class type
shall have a user-declared default constructor.
Why is that? Why can't a const B constructed the same way as a
non-const B, using the implicitly defined default constructor?
Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread
Rationale behind user provided ctor requirement for const objects of non-POD class types Nikos Chantziaras <realnc@arcor.de> - 2011-05-23 12:07 +0300
Re: Rationale behind user provided ctor requirement for const objects of non-POD class types "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-05-23 12:11 +0200
Re: Rationale behind user provided ctor requirement for const objects of non-POD class types Nikos Chantziaras <realnc@arcor.de> - 2011-05-23 13:32 +0300
Re: Rationale behind user provided ctor requirement for const objects of non-POD class types "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-05-23 13:36 +0200
Re: Rationale behind user provided ctor requirement for const objects of non-POD class types "Balog Pal" <pasa@lib.hu> - 2011-05-23 14:44 +0200
Re: Rationale behind user provided ctor requirement for const objects of non-POD class types Öö Tiib <ootiib@hot.ee> - 2011-05-24 16:04 -0700
Re: Rationale behind user provided ctor requirement for const objects of non-POD class types "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-05-25 02:37 +0200
csiph-web