Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Initializing an array class member? Keywords: initializers constructors Message-ID: <586@taumet.com> Date: 5 Feb 91 17:27:10 GMT References: <1991Feb4.215231.16157@alias.uucp> Organization: Taumetric Corporation, San Diego Lines: 26 lfung@alias.UUCP (Lisa A. Fung) writes: >class myClass { > public: > myClass(); // constructor > ~myClass(); // destructor > private: > Tthing arrayOfThings[3]; // Tthing's constructor takes an arg... >}; To initialize an array of objects whose constructor requires arguments, you must provide complete initialization (E&S 12.6.1). If a class has a default constructor (one requiring no arguments), you do not need to provide initializers. For example: struct T1 { T1(int); }; // no default constructor struct T2 { T2(); T2(int); }; // has a default constructor T1 a[3]; // illegal, no default constructor to call T1 b[3] = { T1(1), T1(2), T1(3) }; // ok T2 c[3]; // ok, uses default constructor T2 d[3] = { T2(1), T2(2), T2(3) }; // ok -- Steve Clamage, TauMetric Corp, steve@taumet.com