N
Nikos Chantziaras
(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?
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?