Modular programming

Hi guys,
i want to ask help for modular programming.

How can I let the secondary cpp file have access to the const int variable declared in the primary cpp file??

for instance:

/
primary.cpp

const int a = 55;
/


//secondary.cpp

for(int i=0; i<a; i++){
blah
blah
//

I want the function in secondary cpp to have access of const int a, which was declared in primary cpp.

cheers!!
Declare the variable in a .h file and include that file in both .cpp files
I have a compiler error saying "Redefinition of variables"?? what is that?
then you have declared the value somewhere in your project,,,

use this

 
extern the name of the value;


by the way they should have the same declaration..

Right

1
2
3
4
5
char Cvalue[6] ={0};

somewhere

extern char Cvalue[6];


Wrong

1
2
3
4
5
char Cvalue[6] ={0};

somewhere

extern char Cvalue[4];

Last edited on
I know the error you were talking about and I was kinda hesitant to give that suggestion because I knew it would happen.

Here is a link from stackoverflow that tells you what to do(Basically what joneele said)
http://stackoverflow.com/a/2544872

Similar question asked at DaniWeb:

http://www.daniweb.com/software-development/cpp/threads/131659/how-exactly-to-use-extern
Topic archived. No new replies allowed.