Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: Initializing an array class member? Keywords: initializers constructors Message-ID: <70639@microsoft.UUCP> Date: 12 Feb 91 22:35:29 GMT References: <1991Feb4.215231.16157@alias.uucp> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 35 In article <1991Feb4.215231.16157@alias.uucp> lfung@alias.UUCP (Lisa A. Fung) writes: | |What is the correct syntax for initializing an array class member? |I have tried some combinations, all of which have resulted in syntax |errors with the MacIntosh MPW C++ compiler. If you have an answer, |please e-mail me. Also, if I happened to miss the answer in some C++ book |or other, could you include the reference and page number? | |Here's my example: | |class myClass { | public: | myClass(); // constructor | ~myClass(); // destructor | private: | Tthing arrayOfThings[3]; // Tthing's constructor takes an arg... |}; According to ARM pgs 289-290, your choices are to provide a default constructor for Tthing, or supply values inside the constructor as follows: myClass::myClass() { arrayOfThings[0] = 0; arrayOfThings[1] = 100; arrayOfThings[2] = 200; } This approach would seem to imply that the array is to be default initialized first, which would imply you must have a default Tthing constructor. The ARM goes on to note that there is no syntax for nonstatic const arrays, which I imply to mean that the above are your only two choices for nonstatic nonconst member arrays.