From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9244 invoked by alias); 1 Sep 2004 17:50:32 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 9218 invoked from network); 1 Sep 2004 17:50:29 -0000 Received: from unknown (HELO psmtp.com) (12.158.35.213) by sourceware.org with SMTP; 1 Sep 2004 17:50:29 -0000 Received: from source ([192.150.22.8]) by exprod6ob3.obsmtp.com ([12.158.35.250]) with SMTP; Wed, 01 Sep 2004 10:50:22 PDT Received: from inner-relay-1.corp.adobe.com (inner-relay-1 [153.32.1.51]) by smtp-relay-8.adobe.com (8.12.10/8.12.10) with ESMTP id i81Ho2bA000432; Wed, 1 Sep 2004 10:50:07 -0700 (PDT) Received: from iplan-mn (iplan-mn.corp.adobe.com [130.248.25.5]) by inner-relay-1.corp.adobe.com (8.12.9/8.12.9) with ESMTP id i81Ho1Tk027382; Wed, 1 Sep 2004 10:50:02 -0700 (PDT) Received: from mn-eljay-a51m.adobe.com (b-25-220.corp.adobe.com [130.248.25.220]) by iplan-mn.corp.adobe.com (iPlanet Messaging Server 5.2 HotFix 1.21 (built Sep 8 2003)) with ESMTP id <0I3D00G1PIVD8H@iplan-mn.corp.adobe.com>; Wed, 01 Sep 2004 12:50:01 -0500 (CDT) Date: Wed, 01 Sep 2004 17:50:00 -0000 From: Eljay Love-Jensen Subject: Re: How can I initialize an array whose type is a struct? In-reply-to: X-Sender: eljay@iplan-mn.corp.adobe.com To: learning c++ , gcc-help@gcc.gnu.org Message-id: <6.1.2.0.2.20040901124242.01ec1508@iplan-mn.corp.adobe.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-transfer-encoding: 7BIT References: X-SW-Source: 2004-09/txt/msg00011.txt.bz2 Hi, >How can I initialize an array whose type is a struct? You aren't initializing an array, you are initializing a std::vector. You cannot construct a std::vector that way, as you did in your code. You can construct arrays like that (with the appropriate syntax). For a std::vector, use the push_back method. Also, "iter->days" should be "iter->day". HTH, --Eljay - - - - - - - - - - - - - - - - - - - #include #include #include using std::cout; using std::endl; using std::string; using std::vector; struct year { year(string const& m, int d) : month(m), day(d) { } string month; int day; }; int main() { vector arr; arr.push_back(year("Jan", 31)); arr.push_back(year("Feb", 28)); vector::iterator iter; for(iter = arr.begin(); iter != arr.end(); ++iter) cout << iter->month << " " << iter->day << endl; }