Computing.Net > Forums > Programming > external arrays in c++

external arrays in c++

Reply to Message Icon

Original Message
Name: Josh
Date: August 15, 2002 at 10:11:40 Pacific
Subject: external arrays in c++
Comment:

Well this seems to me to be a silly question to ask and I didn't realize it would be so hard to find an answer to. How can I declare global arrays in a multi-file program so that all the files in the program can access them? I'm using Ms Vc++ and it's not cooperating...I thought it would be a simple matter of sticking a modifier onto the declaration, but that doesnt seem to be working.


Report Offensive Message For Removal


Response Number 1
Name: cup
Date: August 15, 2002 at 10:45:26 Pacific
Reply: (edit)

In header file
extern int array[];

In code file
int array[ARRAYSIZE];


Report Offensive Follow Up For Removal

Response Number 2
Name: Don Arnett
Date: August 15, 2002 at 11:37:54 Pacific
Reply: (edit)

To elaborate a bit on what cup said:

The array declaration (the code file bit) should go in only one .cc or .cpp (or whatever) file and should be placed outside of any functions (usually at the top of the file).

The extern definition should be available to every .cc (.cpp...) file that needs access to the array. Usually this is done by putting it in a header file that is included into every .cc file.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: external arrays in c++

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge