954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to Share a Particular Data object between 2 cpp files

I have an array, which i want it common to both the f1.cpp and f2.cpp .

since f1.cpp will be used to store some values in it and f2.cpp has to use it for some other computations , is there any way i can share these 2 variables .

well i initially thought of files , but they dont completely solve my problem.

rahul8590
Posting Whiz
351 posts since Mar 2009
Reputation Points: 92
Solved Threads: 20
 

Create a header file with:
extern int array[];

in it and include the header in the .cpp file without the array declaration..

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

i didnt completely get u ..

U mean to say
insitlaly i create a header file like

#include
extern int array[];


and then in normal code , i should directly use array ; ?

Will the data stored by the first program into this array can be used by another program .. ?

rahul8590
Posting Whiz
351 posts since Mar 2009
Reputation Points: 92
Solved Threads: 20
 

yes.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: