Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!iamsm.iam.unibe.ch!metz From: metz@iamsm.iam.unibe.ch Newsgroups: gnu.g++.bug Subject: Initialization of array of objects bug (1.36.4) Message-ID: <9002120906.AA00267@bolek.unibe> Date: 12 Feb 90 09:08:44 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 56 >X-Mailer: ELM [version 2.2 PL16] Consider the following program ------------------------------------- #include class A { private: int a; public: A() { cout << "A()\n"; a = 1; } A(int i) { cout << "A(int i) " << i << "\n"; a = i; } ~A() { cout << "~A() " << a << "\n"; } }; int main() { A a; A b[3] = {4, 5}; // array has 3 elements, but only 2 initilizers ! } ------------------------------------- According to C++ 2.0 Ref. Man. p. 81: "Arrays of objects of a class with constructors use constructors in the initilization just like individual objects. If there are fewer objects in the list than elements in the array, the default constructor is used." Here is what I get as output: A() A(int i) 4 A(int i) 5 ~A() 0 ~A() 5 ~A() 4 ~A() 1 NO CONSTRUCTOR CALLED AT ALL!!! The correct output should be A() A(int i) 4 A(int i) 5 A() ~A() 1 ~A() 5 ~A() 4 ~A() 1 Compiler: g++ version 1.36.4 (based on GCC 1.36.93) Lib: libg++ 1.36.2 Igor Metz X400: metz@iam.unibe.ch Institut fuer Informatik ARPA: metz%iam.unibe.ch@relay.cs.net und angewandte Mathematik UUCP: ..!uunet!mcsun!iam.unibe.ch!metz Universitaet Bern Phone: (0041) 31 65 49 90 Switzerland Fax: (0041) 31 65 39 65