🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #363

Re: Arrays as static members

#363
From: Richard
Date: Fri, 02 Jul 1999 00:00
36 lines
1502 bytes
Magnus Hult wrote in message ...
>Hello,
>
>I've got a problem (again). Take a look at this:
>
>class Object {
>    public:
>        int id;
>        static Object *pId[50];
>};
>
>How to allocate memory for those 50 static members? I can't make a loop
>outside a function, and it doesn't feel right to write "Object
>*Object::pId[n] = 0;" 50 times.
>


You need to create the storage at the global scope level (although access
will be restricted to the class scope) as follows in a cpp file ...

Object*    Object::pld[50] ;

That creates the whole array. Then you can use the array from any function
in your class (or in this case anywhere as it's public)

Object::method()
{
    for( int i=0 ; i<50; i++ )
    {
        pld[i] = 0 ;
    }
}

Hope this answers your question

Richard.
Technical Details
Message-ID: <7lhobn$heq$1@ndsukns01.ndsuk.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <qQQe3.1601$nZ5.3455@nntpserver.swip.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f8d38,aecd7aaa6e14dde4
X-Google-Attributes: gidf8d38,public
X-Google-Thread: 109fba,aecd7aaa6e14dde4
X-Google-Attributes: gid109fba,public
X-Google-Thread: 114592,aecd7aaa6e14dde4
X-Google-Attributes: gid114592,public
From: "Richard" <rchandler_mapson@nospam.ndsuk.com>
Subject: Re: Arrays as static members
Date: 1999/07/02
Message-ID: <7lhobn$heq$1@ndsukns01.ndsuk.com>
X-Deja-AN: 496326937
References: <qQQe3.1601$nZ5.3455@nntpserver.swip.net>
Organization: NDS UK
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3612.1700
Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.language,comp.lang.c++