Maxim Yegorushkin
12/3/2008 4:41:00 PM
On Dec 3, 3:50 pm, Yan <yvinogra...@gmail.com> wrote:
> The ISO standard says (in 8.5 [dcl.init] paragraph 9):
>
> 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.
I switched the order of your questions.
> Why is it that the object
> being of const type makes it a special case?
As a constant object can not be assigned to, it must be initialised
where it is declared.
> Does anybody know what is the rationale behind forcing a programmer to
> define a default constructor in this case?
The rationale is to avoid uninitialised constant objects.
Default initialisation of non-PODs does not involve default-
initialisation of POD members, so that they are left uninitialised.
The provided default constructor is supposed to initialise those
members.
--
Max