Topic: array of class objects


Author: Alexander Krotoff <krotoff@such.srcc.msu.su>
Date: 1997/03/27
Raw View
December 96 Draft Standard says:

12.6.1 Explicit initialization [class.expl.init]

3 [Note: if T is a class type with no default constructor, any  declara-
  tion  of  an  object  of type T (or array thereof) is ill-formed if no
  initializer is explicitly specified (see _class.init_ and _dcl.init_). ]

12.1 (Construtors) [class.ctor]

5 A default constructor for a class X is a constructor of class  X  that
  can  be called without an argument.  If there is no user-declared con-
  structor for class X, a default constructor  is  implicitly  declared.

Does it mean, that the rule in the Note of [class.expl.init] shall newer
work ?

Thank you in advance,
--
Alexander N. Krotoff
Research Computer Center
Moscow State University
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/03/28
Raw View
Alexander Krotoff <krotoff@such.srcc.msu.su> writes:

>December 96 Draft Standard says:
>
>12.6.1 Explicit initialization [class.expl.init]
>
>3 [Note: if T is a class type with no default constructor, any  declara-
>  tion  of  an  object  of type T (or array thereof) is ill-formed if no
>  initializer is explicitly specified (see _class.init_ and _dcl.init_). ]
>
>12.1 (Construtors) [class.ctor]
>
>5 A default constructor for a class X is a constructor of class  X  that
>  can  be called without an argument.  If there is no user-declared con-
>  structor for class X, a default constructor  is  implicitly  declared.
>
>Does it mean, that the rule in the Note of [class.expl.init] shall newer
>work ?

No.  For example, the following is ill-formed:

 struct Foo {
  Foo(int) {}
 };
 Foo foo[1];

There is no implicitly-declared default constructor for this example,
because `Foo' has a user-declared constructor.  There is no
user-declared default constructor either -- the only user-declared
constructor is not a default constructor.  Hence there are no default
constructors at all, and so the note quoted above applies (as do the
relevant normative parts of the draft that it references).

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]